Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: swaggerinfo template for instanceNames #1134

Merged
merged 1 commit into from Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion gen/gen.go
Expand Up @@ -410,7 +410,7 @@ import "github.com/swaggo/swag"
const docTemplate_{{ .InstanceName }} = ` + "`{{ printDoc .Doc}}`" + `

// SwaggerInfo{{ if ne .InstanceName "swagger" }}_{{ .InstanceName }} {{- end }} holds exported Swagger Info so clients can modify it
var SwaggerInfo {{ if ne .InstanceName "swagger" }}_{{ .InstanceName }} {{- end }} = &swag.Spec{
var SwaggerInfo{{ if ne .InstanceName "swagger" }}_{{ .InstanceName }} {{- end }} = &swag.Spec{
Version: {{ printf "%q" .Version}},
Host: {{ printf "%q" .Host}},
BasePath: {{ printf "%q" .BasePath}},
Expand Down
12 changes: 12 additions & 0 deletions gen/gen_test.go
Expand Up @@ -101,6 +101,12 @@ func TestGen_BuildInstanceName(t *testing.T) {
) {
t.Fatal(errors.New("generated go code does not contain the correct default registration sequence"))
}
if !strings.Contains(
string(expectedCode),
"var SwaggerInfo =",
) {
t.Fatal(errors.New("generated go code does not contain the correct default variable declaration"))
}

// Custom name
config.InstanceName = "custom"
Expand All @@ -116,6 +122,12 @@ func TestGen_BuildInstanceName(t *testing.T) {
) {
t.Fatal(errors.New("generated go code does not contain the correct registration sequence"))
}
if !strings.Contains(
string(expectedCode),
"var SwaggerInfo_custom =",
) {
t.Fatal(errors.New("generated go code does not contain the correct variable declaration"))
}

// cleanup
expectedFiles := []string{
Expand Down