From b3f9c556830545beb92e565d07fb78edea2715fb Mon Sep 17 00:00:00 2001 From: Denis Kesarev Date: Thu, 27 Jan 2022 00:46:29 +0300 Subject: [PATCH 1/4] Feature: Generated file name from instanceName --- gen/gen.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gen/gen.go b/gen/gen.go index 105b89c6f..84a37151d 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -176,7 +176,11 @@ func (g *Gen) Build(config *Config) error { } func (g *Gen) writeDocSwagger(config *Config, swagger *spec.Swagger) error { - docFileName := path.Join(config.OutputDir, "docs.go") + var filename = "docs.go" + if config.InstanceName != swag.Name { + filename = config.InstanceName + filename + } + docFileName := path.Join(config.OutputDir, filename) absOutputDir, err := filepath.Abs(config.OutputDir) if err != nil { @@ -201,7 +205,11 @@ func (g *Gen) writeDocSwagger(config *Config, swagger *spec.Swagger) error { } func (g *Gen) writeJSONSwagger(config *Config, swagger *spec.Swagger) error { - jsonFileName := path.Join(config.OutputDir, "swagger.json") + var filename = "swagger.json" + if config.InstanceName != swag.Name { + filename = config.InstanceName + filename + } + jsonFileName := path.Join(config.OutputDir, filename) b, err := g.jsonIndent(swagger) if err != nil { @@ -218,7 +226,11 @@ func (g *Gen) writeJSONSwagger(config *Config, swagger *spec.Swagger) error { } func (g *Gen) writeYAMLSwagger(config *Config, swagger *spec.Swagger) error { - yamlFileName := path.Join(config.OutputDir, "swagger.yaml") + var filename = "swagger.yaml" + if config.InstanceName != swag.Name { + filename = config.InstanceName + filename + } + yamlFileName := path.Join(config.OutputDir, filename) b, err := g.json(swagger) if err != nil { From 72ef1375299a1d75cc60e28e491cacde595da2d6 Mon Sep 17 00:00:00 2001 From: Denis Kesarev Date: Thu, 27 Jan 2022 20:43:53 +0300 Subject: [PATCH 2/4] Fix: test fixes Fix: delim addition to file name if instance name not empty --- gen/gen.go | 6 +++--- gen/gen_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gen/gen.go b/gen/gen.go index 84a37151d..39ed0489b 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -178,7 +178,7 @@ func (g *Gen) Build(config *Config) error { func (g *Gen) writeDocSwagger(config *Config, swagger *spec.Swagger) error { var filename = "docs.go" if config.InstanceName != swag.Name { - filename = config.InstanceName + filename + filename = config.InstanceName + "_" + filename } docFileName := path.Join(config.OutputDir, filename) @@ -207,7 +207,7 @@ func (g *Gen) writeDocSwagger(config *Config, swagger *spec.Swagger) error { func (g *Gen) writeJSONSwagger(config *Config, swagger *spec.Swagger) error { var filename = "swagger.json" if config.InstanceName != swag.Name { - filename = config.InstanceName + filename + filename = config.InstanceName + "_" + filename } jsonFileName := path.Join(config.OutputDir, filename) @@ -228,7 +228,7 @@ func (g *Gen) writeJSONSwagger(config *Config, swagger *spec.Swagger) error { func (g *Gen) writeYAMLSwagger(config *Config, swagger *spec.Swagger) error { var filename = "swagger.yaml" if config.InstanceName != swag.Name { - filename = config.InstanceName + filename + filename = config.InstanceName + "_" + filename } yamlFileName := path.Join(config.OutputDir, filename) diff --git a/gen/gen_test.go b/gen/gen_test.go index c44b32b8f..b6c4e3ec3 100644 --- a/gen/gen_test.go +++ b/gen/gen_test.go @@ -112,9 +112,9 @@ func TestGen_BuildInstanceName(t *testing.T) { // cleanup expectedFiles := []string{ - filepath.Join(config.OutputDir, "docs.go"), - filepath.Join(config.OutputDir, "swagger.json"), - filepath.Join(config.OutputDir, "swagger.yaml"), + filepath.Join(config.OutputDir, config.InstanceName+"_"+"docs.go"), + filepath.Join(config.OutputDir, config.InstanceName+"_"+"swagger.json"), + filepath.Join(config.OutputDir, config.InstanceName+"_"+"swagger.yaml"), } for _, expectedFile := range expectedFiles { if _, err := os.Stat(expectedFile); os.IsNotExist(err) { From 89372ae0975eb3729742519c47798cedec04bcab Mon Sep 17 00:00:00 2001 From: Denis Kesarev Date: Thu, 27 Jan 2022 23:30:52 +0300 Subject: [PATCH 3/4] Fix: test fixes --- gen/gen_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/gen_test.go b/gen/gen_test.go index b6c4e3ec3..607047807 100644 --- a/gen/gen_test.go +++ b/gen/gen_test.go @@ -88,7 +88,7 @@ func TestGen_BuildInstanceName(t *testing.T) { } assert.NoError(t, New().Build(config)) - goSourceFile := filepath.Join(config.OutputDir, "docs.go") + goSourceFile := filepath.Join(config.OutputDir, config.InstanceName+"_"+"docs.go") // Validate default registration name expectedCode, err := ioutil.ReadFile(goSourceFile) From 6a7cabf5374dc8f48de6093a84559c134e1aee9f Mon Sep 17 00:00:00 2001 From: Denis Kesarev Date: Fri, 28 Jan 2022 00:51:12 +0300 Subject: [PATCH 4/4] Fix: test fixes --- gen/gen_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gen/gen_test.go b/gen/gen_test.go index 607047807..0447ec9f5 100644 --- a/gen/gen_test.go +++ b/gen/gen_test.go @@ -88,7 +88,7 @@ func TestGen_BuildInstanceName(t *testing.T) { } assert.NoError(t, New().Build(config)) - goSourceFile := filepath.Join(config.OutputDir, config.InstanceName+"_"+"docs.go") + goSourceFile := filepath.Join(config.OutputDir, "docs.go") // Validate default registration name expectedCode, err := ioutil.ReadFile(goSourceFile) @@ -101,6 +101,7 @@ func TestGen_BuildInstanceName(t *testing.T) { // Custom name config.InstanceName = "custom" + goSourceFile = filepath.Join(config.OutputDir, config.InstanceName+"_"+"docs.go") assert.NoError(t, New().Build(config)) expectedCode, err = ioutil.ReadFile(goSourceFile) if err != nil {