本文整理汇总了Golang中github.com/go-swagger/go-swagger/spec.Swagger.BasePath方法的典型用法代码示例。如果您正苦于以下问题:Golang Swagger.BasePath方法的具体用法?Golang Swagger.BasePath怎么用?Golang Swagger.BasePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/go-swagger/go-swagger/spec.Swagger
的用法示例。
在下文中一共展示了Swagger.BasePath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setSwaggerBasePath
func setSwaggerBasePath(swspec *spec.Swagger, lines []string) error {
var ln string
if len(lines) > 0 {
ln = lines[0]
}
swspec.BasePath = ln
return nil
}
示例2: newSpec
func newSpec(endpoint string) *spec.Swagger {
// TODO enable defaults
// TODO complete swagger metadata and move to diff function
api := new(spec.Swagger)
api.Swagger = "2.0"
api.BasePath = endpoint
api.Info = new(spec.Info)
api.Info.Version = "0.0.0"
api.Info.Title = revel.AppName
api.Info.Description = "Description"
api.Info.TermsOfService = "http://swagger.io/terms/"
api.Info.Contact = new(spec.ContactInfo)
api.Info.Contact.Name = ""
api.Info.Contact.Email = ""
api.Info.Contact.URL = ""
api.Info.License = new(spec.License)
api.Info.License.Name = "LICENSE"
api.Info.License.URL = "URL"
// Now is added on requests to Swaggify.Spec
// TODO check if https is HSTS exclusively or no for revel
// TODO ALSO this can be SSL terminated by proxy so this may need changing
if revel.HttpSsl {
api.Schemes = []string{"https"}
} else {
api.Schemes = []string{"http"}
}
api.Consumes = ContentTypes
api.Produces = ContentTypes
// the Swagger type hoists unexported types for some annoying reason
api.Paths = buildPaths(api.BasePath)
api.Definitions = buildDefinitions(api.BasePath)
return api
}
示例3: generateSwagger
func (g *Generator) generateSwagger() (*spec.Swagger, error) {
contact := &spec.ContactInfo{
Name: "API Support",
URL: "api-suport.url",
Email: "[email protected]",
}
license := &spec.License{
Name: "APACHE-2.0",
URL: "url://to/license",
}
info := new(spec.Info)
info.Description = "API description"
info.Title = "API title"
info.TermsOfService = "url://to/tos"
info.Contact = contact
info.License = license
info.Version = "v1"
sw := new(spec.Swagger)
sw.Swagger = "2.0"
sw.Info = info
// sw.Consumes = []string{"application/x-www-form-urlencoded", "application/json", "application/x-protobuf"}
// sw.Produces = []string{"application/json", "application/x-protobuf"}
// TODO(ceram1): Make this configurable.
sw.BasePath = "/api/"
sw.Host = "authagain.appspot.com"
sw.Paths = new(spec.Paths)
sw.Paths.Paths = make(map[string]spec.PathItem)
sw.Definitions = make(map[string]spec.Schema)
sw.Schemes = []string{"https", "http"}
for _, svc := range g.file.Services {
info.Title = svc.GetName() + " API"
if cmt := g.file.GetCommentText(svc.CommentPath); cmt != nil {
info.Description = *cmt
}
for _, mtd := range svc.Methods {
for _, b := range mtd.Bindings {
var p *spec.PathItem
path := buildPath(b.PathTmpl)
if pi, ok := sw.Paths.Paths[path]; !ok {
p = new(spec.PathItem)
} else {
p = &pi
}
op := g.generateOperation(b)
if b.HTTPMethod == "GET" {
p.Get = op
} else if b.HTTPMethod == "POST" {
p.Post = op
} else if b.HTTPMethod == "PUT" {
p.Put = op
} else if b.HTTPMethod == "DELETE" {
p.Delete = op
} else {
return nil, fmt.Errorf("Unknown http method `%v`", b.HTTPMethod)
}
sw.Paths.Paths[path] = *p
}
}
}
for _, msg := range g.file.Messages {
def := g.generateDefinition(msg)
sw.Definitions[def.Title] = *def
}
sw.Info = info
return sw, nil
}