Skip to content

Commit

Permalink
fix: swaggerinfo template for instanceNames (#1133) (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Syuparn authored Feb 10, 2022
1 parent 7e207e5 commit 1a0a57a
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 1a0a57a

Please sign in to comment.