swaggo / swag

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

Cannot find type definition with having import alias #1291

Open 0xdeface opened 2 years ago

0xdeface commented 2 years ago

Describe the bug Project structure. i have many small apps with own entity and uc, simply look like products -- domain ----- entity ------- products.go brands -- domain ----- entity ------- brands.go salepoint -- domain ----- entity ------- salepoint.go

products.go (bellow)

import  "catalog/internal/core/apps/brands/domain"
    salePoint "catalog/internal/core/apps/salepoint/domain"
type Product struct {
     Brand         *domain.Brand `json:"brand"`
     SalePoint   *salePoint.SalePoint `json:"sale_point"`
}

only one field (without alias) can be found during parsing.

in other layer i have

type SingleProductResponseV2 struct {
    core.BaseResponse
    Payload domain.Product `json:"payload"`
}
type ProductRequest struct {
    domain.Product
    ImageFile *multipart.FileHeader `form:"imageFile" json:"imageFile"`
}
// EditProductHandlerV2
// @Schemes
// @Accept mpfd
// @Description "изменение товара"
// @Param uuid path string true "product uuid"
// @Param payload formData ProductRequest true "payload product"
// @Success 200 {object} SingleProductResponseV2
// @Router /v2/products/{uuid} [put]
func (h *Handlers) EditProductHandlerV2(ctx *gin.Context) {}

Expected behavior generate api schema

Screenshots screenshot

Your swag version e.g. 1.8.4

Your go version e.g. 1.19.0

Desktop (please complete the following information):

ubogdan commented 2 years ago

This is a well know issue that never got fixed. It's related to having the same package name too many times.

An untested workaround may be to alias all the imports for domain packages with a unique alias.

sdghchj commented 2 years ago

I remember I fixed it one or two years ago