swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.76k stars 270 forks source link

cannot find type definition: errors.NewError #229

Closed opvexe closed 2 years ago

opvexe commented 2 years ago
╰─± swag init
2022/08/17 16:10:43 Generate swagger docs....
2022/08/17 16:10:43 Generate general API Info, search dir:./
2022/08/17 16:10:43 ParseComment error in file /Users/taoshumin_vendor/go/src/test.io/wsm/server/http_server_ctl.go :cannot find type definition: errors.NewError
╰─± swag -version
swag version v1.8.1
image
╰─± tree
.
├── README.md
├── cmd
│   ├── openurl_unix.go
│   ├── openurl_windows.go
│   ├── root.go
│   ├── server.go
│   ├── upgrade
│   │   └── upgrade.go
│   └── upgrade.go
├── core
│   ├── client.go
│   ├── client_test.go
│   └── istio.go
├── docs
│   ├── docs.go
│   ├── swagger.json
│   └── swagger.yaml
├── errors
│   ├── doc.go
│   ├── errors.go
│   └── errors_test.go
├── go.mod
├── go.sum
├── log
│   ├── log.go
│   └── log_test.go
├── main.go
├── render
│   ├── mock
│   │   ├── errors
│   │   │   └── errors.go
│   │   └── render.go
│   └── render.go
├── server
│   ├── error.go
│   ├── http_api.go
│   ├── http_server_ctl.go
│   ├── http_server_mesh.go
│   ├── http_server_ws.go
│   ├── middleware_cors.go
│   ├── middleware_realip.go
│   ├── middleware_recoverer.go
│   ├── middleware_request_id.go
│   ├── middleware_skip_options.go
│   ├── server.go
│   └── server_test.go
└── services
    ├── controller.go
    ├── controller_test.go
    ├── dr
    │   ├── cache.go
    │   └── handler.go
    ├── gw
    │   ├── cache.go
    │   └── handler.go
    ├── informer.go
    └── vs
        ├── cache.go
        └── handler.go
image image
ubogdan commented 2 years ago

You need to describe what the response would look like.

Try @success 200 {object} errors.Error

opvexe commented 2 years ago

You need to describe what the response would look like.

Try @success 200 {object} errors.Error

    _ "yho.io/wsm/errors"

Doing this will compile the past.

    Err  error `json:"-"`
opvexe commented 2 years ago

You need to describe what the response would look like.

Try @success 200 {object} errors.Error

There seems to be a problem with introducing an external third party?

image
± swag init --parseDependency --parseInternal
2022/08/17 17:58:52 Generate swagger docs....
2022/08/17 17:58:52 Generate general API Info, search dir:./
2022/08/17 17:58:52 Generating errors.Error
2022/08/17 17:58:52 ParseComment error in file /Users/taoshumin_vendor/go/src/test.io/wsm/server/http_server_mesh.go :missing required param comment parameters "data body v1alpha3.Gateway"
ubogdan commented 2 years ago

Try to alias the import.

opvexe commented 2 years ago

alias

alias don't seem to work.

image
opvexe commented 2 years ago

Try to alias the import.

swag init --parseDependency -g main.go

this way can solve .

image
opvexe commented 2 years ago

Try to alias the import.

May I ask you another question? How to write struct generics? Why do I write an error like this?

type SortConstraint interface {
    *v1alpha3.Gateway | *v1alpha3.DestinationRule | *v1alpha3.VirtualService
}

type oldestFirst[T SortConstraint] []*T

func (q oldestFirst[T]) Len() int { return len(q) }
func (q oldestFirst) Less(a, b int) bool {
    return q[a].CreationTimestamp.Time.After(q[b].CreationTimestamp.Time)
}
func (q oldestFirst) Swap(a, b int) { q[a], q[b] = q[b], q[a] }
image
ubogdan commented 2 years ago

The generics support is in the early stage of development. Not sure if it's possible. Anyway, you need to describe a response object and you can better use a DTO for that.