swag
swag copied to clipboard
swaggertype:"primitive,file" is not support on basic type in struct
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:
- Declare parameters like this:
// @Param request formData inout.ProfileInput true "Profile input form"
- Declare the struct input and use it in the declarative Swagger generate comment.
- Run the generate command.
- 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
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
"I am aware that I can use swaggertype:"primitive,string" format:"binary"
as an alternative, but it's not exactly what I need."
I'm having the same issue
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"
Hi, any news about this ?
Your comment @sdghchj is not scallable at all if we have to remove property of our struct