Skip to content

Commit

Permalink
fix: swaggerinfo template for instanceNames (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Syuparn committed Feb 10, 2022
1 parent 7e207e5 commit 9b56776
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit 9b56776

Please sign in to comment.