diff --git a/gen/gen.go b/gen/gen.go index 0eacfa5b1..433700e2d 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -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}}, diff --git a/gen/gen_test.go b/gen/gen_test.go index 0802556aa..973846f46 100644 --- a/gen/gen_test.go +++ b/gen/gen_test.go @@ -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" @@ -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{