Added SwaggerDoc() in api-server

This commit is contained in:
Anastasis Andronidis 2015-07-25 03:33:03 +02:00
parent 9f21ae21e8
commit ff2fcd43f7
2 changed files with 19 additions and 3 deletions

View File

@ -52,6 +52,11 @@ type action struct {
Namer ScopeNamer
}
// An interface to see if an object supports swagger documentation as a method
type documentable interface {
SwaggerDoc() map[string]string
}
// errEmptyName is returned when API requests do not fill the name section of the path.
var errEmptyName = errors.NewBadRequest("name must be provided")
@ -796,7 +801,11 @@ func addObjectParams(ws *restful.WebService, route *restful.RouteBuilder, obj in
if len(jsonName) == 0 {
continue
}
desc := sf.Tag.Get("description")
var desc string
if docable, ok := obj.(documentable); ok {
desc = docable.SwaggerDoc()[jsonName]
}
route.Param(ws.QueryParameter(jsonName, desc).DataType(typeToJSON(sf.Type.Name())))
}
}

View File

@ -247,11 +247,18 @@ func (*SimpleRoot) IsAnAPIObject() {}
type SimpleGetOptions struct {
api.TypeMeta `json:",inline"`
Param1 string `json:"param1" description:"description for param1"`
Param2 string `json:"param2" description:"description for param2"`
Param1 string `json:"param1"`
Param2 string `json:"param2"`
Path string `json:"atAPath"`
}
func (SimpleGetOptions) SwaggerDoc() map[string]string {
return map[string]string{
"param1": "description for param1",
"param2": "description for param2",
}
}
func (*SimpleGetOptions) IsAnAPIObject() {}
type SimpleList struct {