wI2L / fizz

:lemon: Gin wrapper with OpenAPI 3 spec generation
https://pkg.go.dev/github.com/wI2L/fizz
MIT License
214 stars 52 forks source link

HeaderTag now working in input struct #58

Closed ipfans closed 3 years ago

ipfans commented 3 years ago

Hi, I try to use fizz to work with tonic, but I found HeaderTag not working for input struct. Because fizz not support OpenAPI security, so I tried to use header tag to some goal.

For example:

type Info struct {
    Authorization string `header:"Authorization" description:"token" example:"Bear xxxxxxxx"`

    Name    string    `json:"name" validate:"required" example:"banana"`
    Origin  string    `json:"origin" validate:"required" description:"Country of origin of the fruit" enum:"ecuador,france,senegal,china,spain"`
    Price   float64   `json:"price" validate:"required" description:"Price in euros" example:"5.13"`
    AddedAt time.Time `json:"-" binding:"-" description:"Date of addition of the fruit to the market"`
}

The result become to :

    RestInfo:
      type: object
      properties:
        Authorization:
          type: string
          description: Token
          example: Bear xxxxxxxx
        name:
          type: string
          example: banana
        origin:
          type: string
          description: Country of origin of the fruit
          enum:
          - ecuador
          - france
          - senegal
          - china
          - spain
        price:
          type: number
          description: Price in euros
          format: double
          example: 5.13
      required:
      - name
      - origin
      - price
wI2L commented 3 years ago

I'm not sure I understood your issue. Could you please produce a reproductible example of what's your trying to achieve please ?

Alternatively, you could check-out the examples. The FruitIdentityParams input has a field binded to a Header.

Btw,

Authorization string `header:"Authorization" description:"token" example:"Bear xxxxxxxx"`

this field should probably not be part of that input struct, but rather handled by an authentication middleware upstream.

Because fizz not support OpenAPI security

There is an open PR #50 about that.

ipfans commented 3 years ago

@wI2L oh I see, thanks a lot. Waiting for this pr to merge.