diff --git a/pkg/apiserver/api_installer.go b/pkg/apiserver/api_installer.go index c7e53f12bc9..73a5c4ca068 100644 --- a/pkg/apiserver/api_installer.go +++ b/pkg/apiserver/api_installer.go @@ -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()))) } } diff --git a/pkg/apiserver/apiserver_test.go b/pkg/apiserver/apiserver_test.go index ab2ccd484ee..80b9dc218e1 100644 --- a/pkg/apiserver/apiserver_test.go +++ b/pkg/apiserver/apiserver_test.go @@ -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 {