Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
openapigen: expand func map with more utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ucirello committed Oct 10, 2019
1 parent 3aa8726 commit 7ff1a8a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"log"
"os"
"path/filepath"
"sort"
"strings"
tplText "text/template"

Expand Down Expand Up @@ -104,6 +105,13 @@ func main() {
Execute(wr io.Writer, data interface{}) error
}
funcs := map[string]interface{}{
"firstLetter": func(s string) string {
if len(s) == 0 {
return ""
}
return string(s[0])
},
"toLower": strings.ToLower,
"camel": strcase.ToCamel,
"lowerCamel": strcase.ToLowerCamel,
"snake": strcase.ToSnake,
Expand All @@ -120,6 +128,48 @@ func main() {
}
return buf.String(), nil
},
"uniquePathTags": func() []string {
var tags []string
for _, pathItem := range swagger.Paths {
if pathItem.Connect != nil {
tags = append(tags, pathItem.Connect.Tags...)
}
if pathItem.Delete != nil {
tags = append(tags, pathItem.Delete.Tags...)
}
if pathItem.Get != nil {
tags = append(tags, pathItem.Get.Tags...)
}
if pathItem.Head != nil {
tags = append(tags, pathItem.Head.Tags...)
}
if pathItem.Options != nil {
tags = append(tags, pathItem.Options.Tags...)
}
if pathItem.Patch != nil {
tags = append(tags, pathItem.Patch.Tags...)
}
if pathItem.Post != nil {
tags = append(tags, pathItem.Post.Tags...)
}
if pathItem.Put != nil {
tags = append(tags, pathItem.Put.Tags...)
}
if pathItem.Trace != nil {
tags = append(tags, pathItem.Trace.Tags...)
}
}
tagsDict := make(map[string]struct{})
for _, tag := range tags {
tagsDict[tag] = struct{}{}
}
uniqTags := []string{}
for tag := range tagsDict {
uniqTags = append(uniqTags, tag)
}
sort.Strings(uniqTags)
return uniqTags
},
}
switch {
case *isHTML:
Expand Down

0 comments on commit 7ff1a8a

Please sign in to comment.