本文整理匯總了Golang中github.com/raphael/goa/design.APIDefinition.IterateResponses方法的典型用法代碼示例。如果您正苦於以下問題:Golang APIDefinition.IterateResponses方法的具體用法?Golang APIDefinition.IterateResponses怎麽用?Golang APIDefinition.IterateResponses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/raphael/goa/design.APIDefinition
的用法示例。
在下文中一共展示了APIDefinition.IterateResponses方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: New
// New creates a Swagger spec from an API definition.
func New(api *design.APIDefinition) (*Swagger, error) {
if api == nil {
return nil, nil
}
tags, err := tagsFromDefinition(api.Metadata)
if err != nil {
return nil, err
}
params, err := paramsFromDefinition(api.BaseParams, api.BasePath)
if err != nil {
return nil, err
}
var paramMap map[string]*Parameter
if len(params) > 0 {
paramMap = make(map[string]*Parameter, len(params))
for _, p := range params {
paramMap[p.Name] = p
}
}
s := &Swagger{
Swagger: "2.0",
Info: &Info{
Title: api.Title,
Description: api.Description,
TermsOfService: api.TermsOfService,
Contact: api.Contact,
License: api.License,
Version: "",
},
Host: api.Host,
BasePath: api.BasePath,
Paths: make(map[string]*Path),
Schemes: api.Schemes,
Consumes: []string{"application/json"},
Produces: []string{"application/json"},
Parameters: paramMap,
Tags: tags,
ExternalDocs: docsFromDefinition(api.Docs),
}
err = api.IterateResponses(func(r *design.ResponseDefinition) error {
res, err := responseSpecFromDefinition(s, api, r)
if err != nil {
return err
}
if s.Responses == nil {
s.Responses = make(map[string]*Response)
}
s.Responses[r.Name] = res
return nil
})
if err != nil {
return nil, err
}
err = api.IterateResources(func(res *design.ResourceDefinition) error {
return res.IterateActions(func(a *design.ActionDefinition) error {
for _, route := range a.Routes {
if err := buildPathFromDefinition(s, api, route); err != nil {
return err
}
}
return nil
})
})
if err != nil {
return nil, err
}
if len(genschema.Definitions) > 0 {
s.Definitions = make(map[string]*genschema.JSONSchema)
for n, d := range genschema.Definitions {
// sad but swagger doesn't support these
d.Media = nil
d.Links = nil
s.Definitions[n] = d
}
}
return s, nil
}