Skip to content

Commit faabb20

Browse files
authored
Merge pull request #350 from go-generalize/fix/swaggo-get-doc
Fix swaggo get doc
2 parents 5b5c3f1 + 289cbc5 commit faabb20

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

pkg/server/swaggen.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ func (g *Generator) generateSwagComment(ep *parser.Endpoint) string {
3333
for k, v := range obj.Entries {
3434
t, attrs := getSwagType(v.Type)
3535

36-
param, ok := reflect.StructTag(v.RawTag).Lookup("param")
36+
structTag := reflect.StructTag(v.RawTag)
37+
38+
param, ok := structTag.Lookup("param")
3739
if !ok {
3840
param = k
3941
}
@@ -45,7 +47,11 @@ func (g *Generator) generateSwagComment(ep *parser.Endpoint) string {
4547
if _, ok := placeholders[param]; ok {
4648
params = append(params, fmt.Sprintf(`// @Param %s path %s %v "%s"%s`+"\n", param, t, true, k, attrs))
4749
} else if ep.Method == parser.GET {
48-
params = append(params, fmt.Sprintf(`// @Param %s query %s %v "%s"%s`+"\n", k, t, !v.Optional, k, attrs))
50+
example, ok := structTag.Lookup("example")
51+
if !ok {
52+
example = k
53+
}
54+
params = append(params, fmt.Sprintf(`// @Param %s query %s %v "%s"%s`+"\n", k, t, !v.Optional, example, attrs))
4955
}
5056
}
5157

samples/standard/api/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717

1818
// GetRequest ...
1919
type GetRequest struct {
20-
Param string
20+
Param string `example:"param param param"`
2121
Time time.Time
2222
Enum Enum
2323
}

samples/standard/clients/go/classes/types.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/standard/server/mock/controller/get.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)