1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 10:10:53 +00:00

Improve swagger (Main params,yaml

This commit is contained in:
Sergey Lanzman 2016-09-15 00:09:54 +03:00
parent 6189e101c9
commit 1b75ccb9fe

View File

@ -31,6 +31,8 @@ import (
"strings" "strings"
"unicode" "unicode"
"gopkg.in/yaml.v2"
"github.com/astaxie/beego/swagger" "github.com/astaxie/beego/swagger"
"github.com/astaxie/beego/utils" "github.com/astaxie/beego/utils"
) )
@ -83,10 +85,18 @@ func generateDocs(curpath string) {
rootapi.Infos.TermsOfService = strings.TrimSpace(s[len("@TermsOfServiceUrl"):]) rootapi.Infos.TermsOfService = strings.TrimSpace(s[len("@TermsOfServiceUrl"):])
} else if strings.HasPrefix(s, "@Contact") { } else if strings.HasPrefix(s, "@Contact") {
rootapi.Infos.Contact.EMail = strings.TrimSpace(s[len("@Contact"):]) rootapi.Infos.Contact.EMail = strings.TrimSpace(s[len("@Contact"):])
} else if strings.HasPrefix(s, "@Name") {
rootapi.Infos.Contact.Name = strings.TrimSpace(s[len("@Name"):])
} else if strings.HasPrefix(s, "@URL") {
rootapi.Infos.Contact.URL = strings.TrimSpace(s[len("@URL"):])
} else if strings.HasPrefix(s, "@License") { } else if strings.HasPrefix(s, "@License") {
rootapi.Infos.License.Name = strings.TrimSpace(s[len("@License"):]) rootapi.Infos.License.Name = strings.TrimSpace(s[len("@License"):])
} else if strings.HasPrefix(s, "@LicenseUrl") { } else if strings.HasPrefix(s, "@LicenseUrl") {
rootapi.Infos.License.URL = strings.TrimSpace(s[len("@LicenseUrl"):]) rootapi.Infos.License.URL = strings.TrimSpace(s[len("@LicenseUrl"):])
} else if strings.HasPrefix(s, "@Schemes") {
rootapi.Schemes = strings.Split(strings.TrimSpace(s[len("@Schemes"):]), ",")
} else if strings.HasPrefix(s, "@Host") {
rootapi.Host = strings.TrimSpace(s[len("@Host"):])
} }
} }
} }
@ -155,16 +165,20 @@ func generateDocs(curpath string) {
} }
os.Mkdir(path.Join(curpath, "swagger"), 0755) os.Mkdir(path.Join(curpath, "swagger"), 0755)
fd, err := os.Create(path.Join(curpath, "swagger", "swagger.json")) fd, err := os.Create(path.Join(curpath, "swagger", "swagger.json"))
fdyml, err := os.Create(path.Join(curpath, "swagger", "swagger.yml"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer fdyml.Close()
defer fd.Close() defer fd.Close()
dt, err := json.MarshalIndent(rootapi, "", " ") dt, err := json.MarshalIndent(rootapi, "", " ")
if err != nil { dtyml, erryml := yaml.Marshal(rootapi)
if err != nil || erryml != nil {
panic(err) panic(err)
} }
_, err = fd.Write(dt) _, err = fd.Write(dt)
if err != nil { _, erryml = fdyml.Write(dtyml)
if err != nil || erryml != nil {
panic(err) panic(err)
} }
} }