swaggo / swag

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

cannot find type definition: sql.NullTime #1739

Open EAS-Rhys opened 10 months ago

EAS-Rhys commented 10 months ago

Describe the bug When executing: swag init --md ./docs --parseInternal --parseDependency --parseDepth 2 Receiving error: ParseComment error in file /Users/morgan/leadgen/data-ms/routes/content.go :cannot find type definition: sql.NullTime

To Reproduce Steps to reproduce the behavior: Execute swag init --md ./docs --parseInternal --parseDependency --parseDepth 2 with a gorm model in your swagger comment spec.

Example:

Gorm Model:

import (
    "gorm.io/gorm"
    "time"
)
type Content struct {
    gorm.Model
    OrganisationId  int        `json:"organisation_id"`
    ContentTypeId   int        `json:"content_type_id"`
    AvailableDatetime *time.Time `json:"available_datetime"`
    ExpiryDatetime  *time.Time `json:"expiry_datetime"`
    Pinned          bool       `json:"pinned"`
    MediaId         int        `json:"media_id"`
}

Swagger Comment:

// @Summary      List Content in Organisation
// @Description  Get a list of content in the organisation.
// @Tags         content
// @Produce      json
// @Param        orgId path int true "Organization ID" minimum(1)
// @Success      200  {array}  models.Content
// @Router       /organizations/{orgId}/content [get]

Expected behavior Swagger docs to be generated successfully

Your swag version

github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.2

Your go version e.g. 1.21.5

Additional info: I have tried the solution specified in https://github.com/swaggo/swag/issues/1228 with .swaggo file in the root of the project but am still getting this issue.

Gorm version: gorm.io/gorm v1.25.5

sdghchj commented 10 months ago

debug it.

EAS-Rhys commented 10 months ago

debug it.

I've tried, or i wouldn't have raised it as a bug. If there is something you think i'm missing can you at least give me a pointer?

sdghchj commented 10 months ago

You have to check your swag version by cmd swag --version. The swag version means the version of the swag tool you are using, other than the dependent package version you have imported.

sdghchj commented 10 months ago

I have also tried model you gave above with the newest swag tool. It work well.

chenzhiguo commented 2 months ago

Same issue

stanlyzoolo commented 2 months ago

use swaggertype: "string"

AvailableDatetime sql.NullTime `json:"available_datetime" swaggertype: "string"`