'Swagger generation is ignoring SecurityDefiniton

Cannot understand one thing, why swag init command is generating everything, except SecurityDefinition block

For example, this is my code on main function:

// @title Swagger API
// @version 1.0
// @description This is a documentation for PlatOps Core tool.
// @termsOfService http://platops.com/
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host test.com
// @BasePath /v2
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization

And how I'm using :

// GetUser godoc
// @Summary Retrieves users list
// @Tags users
// @Accept json
// @Produce json
// @Success 200 {object} string
// @Failure 400,404 {object} string
// @Failure 500 {object} string
// @Router /api/users/ [get]
// @Security Bearer

From this, it's generating everything, this path also, but no SecurityDefinition block inside.

I'm trying to implement this one: https://github.com/swaggo/swag#security

P.S. If I put already generated text on the generated doc file, it's working... so why it cannot generate it?

"securityDefinitions": {
        "api_key": {
            "type": "apiKey",
            "name": "Bearer",
            "in": "header"
        },
}


Solution 1:[1]

Add your security definitions in the file which you are passing in the swag init -g flag... Mostly it should be your main.go file... it should show up once you do that

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vinitkumar S Gaikwad