From 1a0a57a149e0bb5b438ca00b22081507f38d97e1 Mon Sep 17 00:00:00 2001 From: Syuparn Date: Thu, 10 Feb 2022 22:13:05 +0900 Subject: [PATCH] fix: swaggerinfo template for instanceNames (#1133) (#1134) --- gen/gen.go | 2 +- gen/gen_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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{