diff --git a/gen/gen.go b/gen/gen.go index 105b89c6f..39ed0489b 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 { diff --git a/gen/gen_test.go b/gen/gen_test.go index c44b32b8f..0447ec9f5 100644 --- a/gen/gen_test.go +++ b/gen/gen_test.go @@ -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 { @@ -112,9 +113,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) {