swag icon indicating copy to clipboard operation
swag copied to clipboard

Error cannot find type definition: decimal.NullDecimal

Open dungtranhoang opened this issue 2 years ago • 4 comments
trafficstars

Describe the bug I create a struct with decimal.NullDecimal inside then when generate swaggo got this error Error cannot find type definition: decimal.NullDecimal

To Reproduce Steps to reproduce the behavior:

  1. Create a struct with decimal.NullDecimal field
  2. Swag init

Expected behavior Generate normally like decimal.Decimal

Your swag version swag version v1.8.10

Your go version go version go1.20 linux/amd64

Desktop (please complete the following information):

  • OS: Windows 10
  • Version: 21H2 (OS Build 19044.2965)

dungtranhoang avatar May 22 '23 06:05 dungtranhoang

If the type is internal you have to add the flag --parseInternal, if its from a dependency use --parseDependency

swag init --parseDependency --parseInternal

mariusgassen avatar May 22 '23 11:05 mariusgassen

Hi all!) I have the same issue with: swag init --parseInternal --parseDepth 2 -g path/to/my/main.go

Output: cannot find type definition: sql.NullTime

Maybe there are other solutions to resolve this issue?

stanlyzoolo avatar Sep 12 '23 07:09 stanlyzoolo

stanlyzoolo

I have another solution, make the .swaggo file among with your go.mod Content inside .swaggo will be

replace JsonNullBool boolean
replace JsonNullNumber integer
replace JsonNullNumberStr string
replace decimal.NullDecimal number

maybe your case will be replace sql.NullTime string

dungtranhoang avatar Sep 12 '23 07:09 dungtranhoang

Thanks for an advice) I found a the better solution by adding swaggertype:"string" tag for selected sql.NullTime type. Take a look here --> https://github.com/swaggo/swag#use-swaggertype-tag-to-supported-custom-type

It works well for me :+1:

stanlyzoolo avatar Sep 12 '23 13:09 stanlyzoolo