Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger fail with gorm #4

Open
ZiplEix opened this issue Jun 30, 2023 · 0 comments
Open

swagger fail with gorm #4

ZiplEix opened this issue Jun 30, 2023 · 0 comments

Comments

@ZiplEix
Copy link

ZiplEix commented Jun 30, 2023

When using gorm as The ORM to use Postgresql the generation of the swagger documentation fail.
here is my todo model:

package models

import "gorm.io/gorm"

type Todo struct {
	gorm.Model
	Title     string `json:"title" gorm:"text;not null;default:null"`
	Completed bool   `json:"completed" gorm:"not null;default:false"`
}

and here the error of the swag command (swag init --dir ./,./handlers) (Running on a docker but thje same append if running locally)

 > [7/7] RUN swag init --dir ./,./handlers:                                           
#0 0.545 2023/06/30 17:11:43 Generate swagger docs....                                
#0 0.545 2023/06/30 17:11:43 Generate general API Info, search dir:./                 
#0 1.030 2023/06/30 17:11:43 Generate general API Info, search dir:./handlers         
#0 1.118 2023/06/30 17:11:43 Generating models.Todo                                   
#0 1.118 2023/06/30 17:11:43 Error parsing type definition 'models.Todo': cannot find type definition: gorm.Model
#0 1.118 2023/06/30 17:11:43 ParseComment error in file /usr/src/app/handlers/todos.go :cannot find type definition: gorm.Model

For info here is my dockerfile:

FROM golang:1.20.2

WORKDIR /usr/src/app

RUN go install github.com/cosmtrek/air@latest
RUN go install github.com/swaggo/swag/cmd/swag@latest

COPY . .

RUN go mod tidy

RUN swag init --dir ./,./handlers

And my go.mod file:

module github.com/ZiplEix/API_template

go 1.20

require github.com/gofiber/swagger v0.1.12

require (
	github.com/KyleBanks/depth v1.2.1 // indirect
	github.com/PuerkitoBio/purell v1.2.0 // indirect
	github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
	github.com/andybalholm/brotli v1.0.5 // indirect
	github.com/go-openapi/jsonpointer v0.19.5 // indirect
	github.com/go-openapi/jsonreference v0.19.6 // indirect
	github.com/go-openapi/spec v0.20.4 // indirect
	github.com/go-openapi/swag v0.19.15 // indirect
	github.com/gofiber/fiber/v2 v2.47.0 // indirect
	github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
	github.com/google/uuid v1.3.0 // indirect
	github.com/jackc/pgpassfile v1.0.0 // indirect
	github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
	github.com/jackc/pgx/v5 v5.3.1 // indirect
	github.com/jinzhu/inflection v1.0.0 // indirect
	github.com/jinzhu/now v1.1.5 // indirect
	github.com/joho/godotenv v1.5.1 // indirect
	github.com/josharian/intern v1.0.0 // indirect
	github.com/klauspost/compress v1.16.3 // indirect
	github.com/mailru/easyjson v0.7.6 // indirect
	github.com/mattn/go-colorable v0.1.13 // indirect
	github.com/mattn/go-isatty v0.0.19 // indirect
	github.com/mattn/go-runewidth v0.0.14 // indirect
	github.com/philhofer/fwd v1.1.2 // indirect
	github.com/rivo/uniseg v0.2.0 // indirect
	github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
	github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
	github.com/swaggo/files/v2 v2.0.0 // indirect
	github.com/swaggo/swag v1.16.1 // indirect
	github.com/tinylib/msgp v1.1.8 // indirect
	github.com/valyala/bytebufferpool v1.0.0 // indirect
	github.com/valyala/fasthttp v1.47.0 // indirect
	github.com/valyala/tcplisten v1.0.0 // indirect
	golang.org/x/crypto v0.10.0 // indirect
	golang.org/x/net v0.10.0 // indirect
	golang.org/x/sys v0.9.0 // indirect
	golang.org/x/text v0.10.0 // indirect
	golang.org/x/tools v0.7.0 // indirect
	gopkg.in/yaml.v2 v2.4.0 // indirect
	gorm.io/driver/postgres v1.5.2 // indirect
	gorm.io/gorm v1.25.2 // indirect
)

Does anyone have a solution ?

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

No branches or pull requests

1 participant