Skip to content

Commit

Permalink
操作的描述ApiHandler.Desc在swagger中支持多行自适应显示
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed May 27, 2016
1 parent d3cb88a commit 23797b5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions swagger/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func resetApidoc(host string) {
virtRouter = lessgo.RootRouter()
rootTag := &Tag{
Name: virtRouter.Path(),
Description: virtRouter.Description(),
Description: tagDesc(virtRouter.Description()),
}
apidoc = &Swagger{
Version: SwaggerVersion,
Expand Down Expand Up @@ -139,7 +139,7 @@ func resetApidoc(host string) {
}
childTag := &Tag{
Name: child.Path(),
Description: child.Description(),
Description: tagDesc(child.Description()),
}
apidoc.Tags = append(apidoc.Tags, childTag)
for _, grandson := range child.Children {
Expand All @@ -149,7 +149,7 @@ func resetApidoc(host string) {
}
grandsonTag := &Tag{
Name: grandson.Path(),
Description: grandson.Description(),
Description: tagDesc(grandson.Description()),
}
apidoc.Tags = append(apidoc.Tags, grandsonTag)
for _, vr := range grandson.Progeny() {
Expand All @@ -175,8 +175,8 @@ func addpath(vr *lessgo.VirtRouter, tag *Tag) {
}
o := &Opera{
Tags: []string{tag.Name},
Summary: vr.Description(),
Description: vr.Description(),
Summary: summary(vr.Description()),
Description: desc(vr.Description()),
OperationId: vr.Id,
Consumes: CommonMIMETypes,
Produces: CommonMIMETypes,
Expand Down Expand Up @@ -287,6 +287,18 @@ func createPath(vr *lessgo.VirtRouter) string {
return p
}

func tagDesc(desc string) string {
return strings.TrimSpace(desc)
}

func summary(desc string) string {
return strings.TrimSpace(strings.Split(strings.TrimSpace(desc), "\n")[0])
}

func desc(desc string) string {
return "<pre>" + strings.TrimSpace(desc) + "</pre>"
}

type FileInfo struct {
RelPath string
Size int64
Expand Down

0 comments on commit 23797b5

Please sign in to comment.