swag icon indicating copy to clipboard operation
swag copied to clipboard

swaggertype:"primitive,file" is not support on basic type in struct

Open worapolburaphan opened this issue 1 year ago • 4 comments

Describe the bug I encountered an issue while using the Swaggo repository. Swagger has a basic type called "file" for file uploads (binary). However, when I used swaggertype:"primitive,file" in a struct like the following:

package inout

type ProfileInput struct {
	Title        string                `form:"title" validate:"required"`
	Description  string                `form:"description" validate:"required"`
	ProfileImage *multipart.FileHeader `form:"profile_image" validate:"required_if=cover_image" swaggertype:"primitive,file"`
	CoverImage   *multipart.FileHeader `form:"cover_image" validate:"required_if=profile_image" swaggertype:"primitive,file"`
}

I received the following error message when running the swag init command:

2023/07/01 18:39:59 Error parsing type definition 'inout.ProfileInput': file is not basic types
2023/07/01 18:39:59 Skipping 'inout.ProfileInput', recursion detected.
2023/07/01 18:39:59 ParseComment error in file /app/src/domain/inout/inout.go: recursively parsing struct
failed to build, error: exit status 1

To Reproduce To reproduce the behavior, follow these steps:

  1. Declare parameters like this:
    // @Param request formData inout.ProfileInput true "Profile input form"
    
  2. Declare the struct input and use it in the declarative Swagger generate comment.
  3. Run the generate command.
  4. See the error.

Expected behavior The generation process should be successful, and the "docs" folder should be generated. In the "swagger.yaml" or "swagger.json" file, the type should be specified as "file".

Screenshots Screenshot

swag version Swag version: 2.0

go version Go version: 1.19 Gin version: 1.9.1

Desktop (please complete the following information):

  • OS: MacOS Ventura
  • Browser: -
  • Version: 13.2.1

worapolburaphan avatar Jul 02 '23 07:07 worapolburaphan

"I am aware that I can use swaggertype:"primitive,string" format:"binary" as an alternative, but it's not exactly what I need."

worapolburaphan avatar Jul 02 '23 07:07 worapolburaphan

I'm having the same issue

lhopcroft123 avatar Sep 15 '23 12:09 lhopcroft123

file not supoort in struct.

Just try:

package inout

type ProfileInput struct {
	Title        string                `form:"title" validate:"required"`
	Description  string                `form:"description" validate:"required"`
}


// @Param request           formData inout.ProfileInput true "Profile input form"
// @Param profile_image formData file true "profile image"
// @Param cover_image   formData file true "cover image"

sdghchj avatar Sep 25 '23 07:09 sdghchj

Hi, any news about this ?

Your comment @sdghchj is not scallable at all if we have to remove property of our struct

FournyP avatar Apr 01 '24 19:04 FournyP