Skip to content

Parse error: Struct is not supported for type of header #1197

@rizary

Description

@rizary

Describe the bug
I got parse error when try to use struct as header data type. This is the error:

$ swag init
2022/05/04 16:03:51 Generate swagger docs....
2022/05/04 16:03:51 Generate general API Info, search dir:./
2022/05/04 16:03:51 ParseComment error in file /home/rizary/0chain/0box/code/zboxcore/common/routerV2.go :common.AuthHeader is not supported type for header

To Reproduce
Steps to reproduce the behavior:
Create struct like this:

type AuthHeader struct {
	ClientID    string `header:"X-App-Client-ID" binding:"required example:"f58886e2619986c..." format:"string""`
	PublicKey   string `header:"X-App-Client-Key" binding:"required" example:"d273e4907030947b..." format:"string"`
	Signature   string `header:"X-App-Client-Signature" binding:"-" example:"1234" format:"string"`
	Timestamp   string `header:"X-App-Timestamp" binding:"required" example:"1618213324" format:"string"`
	TokenInput  string `header:"X-App-ID-TOKEN" binding:"required" example:"eyJhbGciOiJSUzI1..." format:"string"`
	PhoneNumber string `header:"X-App-Phone-Number" binding:"required" example:"+917696229925" format:"string"`
}

func (a *AuthHeader) Bind(c *gin.Context) error {
	err := c.ShouldBindHeader(&a)
	if err != nil {
		return err
	}
	return nil
}

have one of the handler commented like this:

// @Summary Create Allocation
// @Description get string by ID
// @ID createallocation
// @Accept  x-www-form-urlencoded
// @Produce  json
// @Param   header header common.AuthHeader true  "AuthHeader"
// @Param   body body handler.AllocCreate true  "AllocCreate"
// @Success 200 {object} models.Allocation
// @Failure 400 {object} common.Error "Unable to create Allocation"
// @Failure 404 {object} common.Error "Bad Request"
// @Failure 500 {object} common.Error "Error creating transaction"
// @Router /v2/createallocation [post]

run: swag init

Expected behavior
The generated swagger.json should at least:

"parameters": {
    "app_client_id":
      {
        "name": "X-App-Client-ID",
        "in": "header",
        "description": "Wallet ID",
        "required": true,
        "type": "string"
      }
}

or in the definitions:{} section.

Screenshots
If applicable, add screenshots to help explain your problem.

Your swag version
1.8.0

Your go version
1.18.0

Desktop (please complete the following information):

  • OS: Linux
  • Browser: Brave
  • Version: Version 1.37.116 Chromium: 100.0.4896.127

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions