Swag: Auto set Authorization header with ApiKeyAuth

Created on 7 Mar 2019  路  3Comments  路  Source: swaggo/swag

Expected behavior

I already set @securityDefinitions.apikey ApiKeyAuth in General API info, and @Security ApiKeyAuth in Each API operation:

@securityDefinitions.apikey ApiKeyAuth
func main() {
}

// @Security ApiKeyAuth
// @router /account/info [get]
func GetAccountInfo(c *gin.Context) {
}

This works great, except that Swagger UI says there is no params needed:

image

This is not correct since Authorization header is needed for the API. After I add @param definition to API:

// @Security ApiKeyAuth
// @param Authorization header string true "Authorization"
// @router /account/info [get]
func GetAccountInfo(c *gin.Context) {
}

Now, Swagger UI is correct:

image

image

But Authorization header is empty when trying out the API.

Is there any way to auto set Authorization header that already set by ApiKeyAuth?

Your swag version
1.4.1

All 3 comments

If you have problem reopen issue.

@pei0804 Does this work for Oauth2Implicit ? It doesn't seem to be sending my Authorization Header after I Authenticate

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wingsofovnia picture wingsofovnia  路  3Comments

JimChung0403 picture JimChung0403  路  3Comments

hoangtuan151 picture hoangtuan151  路  4Comments

welenlin picture welenlin  路  3Comments

piwan picture piwan  路  6Comments