Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Linter fails (#1136) #1137

Merged
merged 3 commits into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions gen/gen.go
Expand Up @@ -84,7 +84,7 @@ type Config struct {
CodeExampleFilesDir string

// InstanceName is used to get distinct names for different swagger documents in the
// same project. The default value is "swagger".
// same project. The default value is "Swagger".
InstanceName string

// ParseDepth dependency parse depth
Expand Down Expand Up @@ -407,21 +407,21 @@ package {{.PackageName}}

import "github.com/swaggo/swag"

const docTemplate_{{ .InstanceName }} = ` + "`{{ printDoc .Doc}}`" + `
const docTemplate{{ .InstanceName }} = ` + "`{{ printDoc .Doc}}`" + `

pilinux marked this conversation as resolved.
Show resolved Hide resolved
// 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{
// 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{
Version: {{ printf "%q" .Version}},
Host: {{ printf "%q" .Host}},
BasePath: {{ printf "%q" .BasePath}},
Schemes: []string{ {{ range $index, $schema := .Schemes}}{{if gt $index 0}},{{end}}{{printf "%q" $schema}}{{end}} },
Title: {{ printf "%q" .Title}},
Description: {{ printf "%q" .Description}},
InfoInstanceName: {{ printf "%q" .InstanceName }},
SwaggerTemplate: docTemplate_{{ .InstanceName }},
SwaggerTemplate: docTemplate{{ .InstanceName }},
pilinux marked this conversation as resolved.
Show resolved Hide resolved
}

func init() {
swag.Register(SwaggerInfo{{ if ne .InstanceName "swagger" }}_{{ .InstanceName }} {{- end }}.InstanceName(), SwaggerInfo{{ if ne .InstanceName "swagger" }}_{{ .InstanceName }} {{- end }})
swag.Register(SwaggerInfo{{ if ne .InstanceName "Swagger" }}{{ .InstanceName }} {{- end }}.InstanceName(), SwaggerInfo{{ if ne .InstanceName "Swagger" }}{{ .InstanceName }} {{- end }})
}
`
6 changes: 3 additions & 3 deletions gen/gen_test.go
Expand Up @@ -109,7 +109,7 @@ func TestGen_BuildInstanceName(t *testing.T) {
}

// Custom name
config.InstanceName = "custom"
config.InstanceName = "Custom"
goSourceFile = filepath.Join(config.OutputDir, config.InstanceName+"_"+"docs.go")
assert.NoError(t, New().Build(config))
expectedCode, err = ioutil.ReadFile(goSourceFile)
Expand All @@ -118,13 +118,13 @@ func TestGen_BuildInstanceName(t *testing.T) {
}
if !strings.Contains(
string(expectedCode),
"swag.Register(SwaggerInfo_custom.InstanceName(), SwaggerInfo_custom)",
"swag.Register(SwaggerInfoCustom.InstanceName(), SwaggerInfoCustom)",
) {
t.Fatal(errors.New("generated go code does not contain the correct registration sequence"))
}
if !strings.Contains(
string(expectedCode),
"var SwaggerInfo_custom =",
"var SwaggerInfoCustom =",
) {
t.Fatal(errors.New("generated go code does not contain the correct variable declaration"))
}
Expand Down
4 changes: 2 additions & 2 deletions swagger.go
Expand Up @@ -7,7 +7,7 @@ import (
)

// Name is a unique name be used to register swag instance.
const Name = "swagger"
const Name = "Swagger"
pilinux marked this conversation as resolved.
Show resolved Hide resolved

var (
swaggerMu sync.RWMutex
Expand Down Expand Up @@ -38,7 +38,7 @@ func Register(name string, swagger Swagger) {
}

// ReadDoc reads swagger document. An optional name parameter can be passed to read a specific document.
// The default name is "swagger".
// The default name is "Swagger".
func ReadDoc(optionalName ...string) (string, error) {
swaggerMu.RLock()
defer swaggerMu.RUnlock()
Expand Down