Skip to content

@schemes annotation doesn't populate SwaggerInfo.Schemes in generated docs.go #2143

@greddy2193

Description

@greddy2193

Describe the bug
The @schemes annotation correctly generates the schemes array in swagger.json and swagger.yaml, but the generated docs.go file has an empty Schemes slice in SwaggerInfo. This causes the runtime template {{ marshal .Schemes }} to render an empty array when serving Swagger UI.

To Reproduce
Steps to reproduce the behavior:

  1. Add // @schemes http https annotation in your main.go
  2. Run swag init
  3. Open generated docs/swagger.json - observe "schemes": ["http", "https"] is correct
  4. Open generated docs/docs.go - observe Schemes: []string{} is empty

Expected behavior
The Generated docs.go should contain:
var SwaggerInfo = &swag.Spec{
Schemes: []string{"http", "https"},
// ...
}

Instead, it generates:
var SwaggerInfo = &swag.Spec{
Schemes: []string{},
// ...
}

Screenshots
If applicable, add screenshots to help explain your problem.

Your swag version
v1.16.4

Your go version
go1.24.2

Desktop (please complete the following information):

  • OS: Windows

Additional context
Current workaround is to set it manually at runtime.
func init() {
docs.SwaggerInfo.Schemes = []string{"http", "https"}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions