swag icon indicating copy to clipboard operation
swag copied to clipboard

Cannot find type definition with having import alias

Open 0xdeface opened this issue 2 years ago • 2 comments

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):

  • OS: linux x64
  • Browser: [chrome, ]
  • Version: [103.0.5060.114 ]

0xdeface avatar Aug 12 '22 04:08 0xdeface

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.

ubogdan avatar Sep 17 '22 20:09 ubogdan

I remember I fixed it one or two years ago

sdghchj avatar Oct 17 '22 08:10 sdghchj