Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the return value defined by the @ Success tag is equal to a null value, a null pointer exception occurs #1653

Closed
addice1019 opened this issue Aug 21, 2023 · 4 comments

Comments

@addice1019
Copy link

addice1019 commented Aug 21, 2023

Describe the bug
When the return value defined by the @ Success tag is equal to a null value, a null pointer exception occurs

To Reproduce
Steps to reproduce the behavior:

  1. Response {data=nil} in the structure
    image

  2. Run the command swag init in cmd
    image

  3. Invalid memory address or nil pointer dereference discovered through debugging
    image

Expected behavior
Can swaggo parse comments in the returned structure that are equal to nil, such as utils. Response {data=nil}
Expected swaggo doc definition

// deleteFile 删除文件
//
//	@Summary		删除文件
//	@Description	删除文件
//	@Tags			member
//	@Accept			json
//	@Produce		json
//	@Param			fileIds	query		string	true	"文件ID集合字符串"
//	@Success		200		{object}	utils.Response{data=nil}
//	@Failure		400		{object}	utils.ErrorResponse
//	@Router			/app/deleteFile [POST]
func deleteFile(c *gin.Context) {
}

Expected JSON return value

{
   "status": 0,
   "message": "success",
   "data": null
}

Your swag version
v1.16.1

Your go version
go1.20.5

Desktop (please complete the following information):

  • OS: [windows 10 19045.3324]
@addice1019 addice1019 changed the title The return value structure defines a null pointer exception with a value equal to nil When the return value defined by the @ Success tag is equal to a null value, a null pointer exception occurs Aug 21, 2023
@sdghchj
Copy link
Member

sdghchj commented Sep 11, 2023

May I ask why need null?

@addice1019
Copy link
Author

The project coexists with the Springboot project and requires a unified JSON return value

@Shimizu1111
Copy link
Contributor

What do you think of the solution in #1667 ?

@Shimizu1111
Copy link
Contributor

@sdghchj
What do you think of the solution in #1667 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants