swag icon indicating copy to clipboard operation
swag copied to clipboard

Security annotations cannot work

Open w570955342 opened this issue 2 years ago • 2 comments

Describe the bug // @title 网络检查服务 // @description 网络检查服务接口文档 // @securityDefinitions.apikey ApiKeyAuth // @in header // @name Authorization // @schemes http https // @BasePath /check // @contact.name zq // @contact.email [email protected] func main() {}

swag v1.8.0 doc.go: // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ Version: "", Host: "", BasePath: "/check", Schemes: []string{"http", "https"}, Title: "网络检查服务", Description: "网络检查服务接口文档", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, }

swag v1.8.6 doc.go: // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ Version: "", Host: "", BasePath: "", Schemes: []string{}, Title: "网络检查服务", Description: "网络检查服务接口文档", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, }

but when I chage main.go,just add a blank line , v1.8.6 works well。 // @title 网络检查服务 // @description 网络检查服务接口文档 // @securityDefinitions.apikey ApiKeyAuth // @in header // @name Authorization

// @schemes http https // @BasePath /check // @contact.name zq // @contact.email [email protected] func main() {}

swag v1.8.6 doc.go: // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ Version: "", Host: "", BasePath: "/check", Schemes: []string{"http", "https"}, Title: "网络检查服务", Description: "网络检查服务接口文档", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, }

To Reproduce Steps to reproduce the behavior:

  1. go install github.com/swaggo/swag/cmd/[email protected]
  2. swag init --generalInfo ./cmd/check/main.go --output ./internal/app/swagger
  3. go install github.com/swaggo/swag/cmd/[email protected]
  4. swag init --generalInfo ./cmd/check/main.go --output ./internal/app/swagger

Expected behavior swag v1.8.6 can work well.

Your swag version 1.8.0 and 1.8.6

Your go version go version go1.18.3 windows/amd64

Desktop (please complete the following information):

  • OS: windows/amd64
  • Browser: [chrome]
  • Version: [105.0.5195.127]

w570955342 avatar Sep 29 '22 08:09 w570955342

// @securitydefinitions.apikey ApiKeyAuth
// @in                         header
// @name                       Authorization

securityDefinitions -> securitydefinitions

does works for me!!!!

maljb avatar Nov 08 '22 13:11 maljb

Moving securitydefinitions annotations above main() function helped me.

by-cx avatar Apr 20 '24 21:04 by-cx