Swag: cannot find type definition: gorm.Model

Created on 16 Oct 2020  路  9Comments  路  Source: swaggo/swag

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

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

swag version
1.6.7

go version

1.15

if use:
swag init --parseVendor true
output:
cannot find type definition: sql.NullTime.

Most helpful comment

I am having the same issue:

2020/10/28 13:52:34 ParseComment error in file _/file/path/_.go **:cannot find type definition: gorm.Model

try swag init --parseDependency --parseInternal

All 9 comments

I see issues 808, but I don't think I should modify Gorm's source code to add "swagger type"

@ruanhailiang I'm afraid we can't help you if you don't use/fill the bug template so we can use a use case example.

鎶撶揣瑙e喅杩欎釜闂

I have the same probleme using the web framework fiber. My struct model was like that,

type Movie struct {
    title    string `json:"title"`
    tagline  string `json:"tagline"`
    released int    `json:"released"`
}

then I put like that,

type Movie struct {
    Title    string `json:"title"`
    Tagline  string `json:"tagline"`
    Released int    `json:"released"`
}

@zhaojingadmin

鎶撶揣瑙e喅杩欎釜闂

Of course, this is an open-source project and contributions are always welcome.

I see issues 808, but I don't think I should modify Gorm's source code to add "swagger type"

Well, this is a code design pattern problem, not a swag problem. (You are exposing to the API some data that you are not in control of and this may lead to wrong output when external package API definitions may change)

Solution: You can use a DTO pattern to solve this issue.
Why: In real-life applications, you don't want to expose your database structure directly to the API for various security reasons so this pattern may be a good approach.

I am having the same issue:

2020/10/28 13:52:34 ParseComment error in file /file/path/.go **:cannot find type definition: gorm.Model

I am having the same issue:

2020/10/28 13:52:34 ParseComment error in file _/file/path/_.go **:cannot find type definition: gorm.Model

try swag init --parseDependency --parseInternal

I am having the same issue:
2020/10/28 13:52:34 ParseComment error in file _/file/path/_.go **:cannot find type definition: gorm.Model

try swag init --parseDependency --parseInternal

Wow thank you! This worked for me.

Was this page helpful?
0 / 5 - 0 ratings