2

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"
        },
}
  • I'm not familiar with the swag implementation, but looking at the documentation it appears that the `securitydefinitions.apikey` might need to be in all lower case. Some of the examples have it written in camel case but if that does matter I assume it's a typo. – Grizzle Jan 12 '21 at 20:28
  • Unfortunately, this is not a reason :( – Alex Jamerton Jan 12 '21 at 20:51
  • do you found a solution? I have the exactly same problem. – NFoerster Nov 01 '22 at 18:12

1 Answers1

0

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