Commit 8694f6f5 authored by Brendan Burns's avatar Brendan Burns

Add return types to PUT, POST and PATCH methods.

Also add return types for proxy and redirect handlers.
parent e44ec497
...@@ -87,6 +87,7 @@ func (a *APIInstaller) newWebService() *restful.WebService { ...@@ -87,6 +87,7 @@ func (a *APIInstaller) newWebService() *restful.WebService {
ws.Consumes("*/*") ws.Consumes("*/*")
ws.Produces(restful.MIME_JSON) ws.Produces(restful.MIME_JSON)
ws.ApiVersion(a.group.Version) ws.ApiVersion(a.group.Version)
return ws return ws
} }
...@@ -158,19 +159,24 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag ...@@ -158,19 +159,24 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
return err return err
} }
var versionedDeleterObject runtime.Object var versionedDeleterObject interface{}
switch { switch {
case isGracefulDeleter: case isGracefulDeleter:
object, err := a.group.Creater.New(serverVersion, "DeleteOptions") objectPtr, err := a.group.Creater.New(serverVersion, "DeleteOptions")
if err != nil { if err != nil {
return err return err
} }
versionedDeleterObject = object versionedDeleterObject = indirectArbitraryPointer(objectPtr)
isDeleter = true isDeleter = true
case isDeleter: case isDeleter:
gracefulDeleter = rest.GracefulDeleteAdapter{deleter} gracefulDeleter = rest.GracefulDeleteAdapter{deleter}
} }
versionedStatusPtr, err := a.group.Creater.New(serverVersion, "Status")
if err != nil {
return err
}
versionedStatus := indirectArbitraryPointer(versionedStatusPtr)
var getOptions runtime.Object var getOptions runtime.Object
var getOptionsKind string var getOptionsKind string
if isGetterWithOptions { if isGetterWithOptions {
...@@ -336,9 +342,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag ...@@ -336,9 +342,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
} }
route := ws.GET(action.Path).To(handler). route := ws.GET(action.Path).To(handler).
Filter(m). Filter(m).
Doc("read the specified " + kind). Doc("read the specified "+kind).
Operation("read" + kind). Operation("read"+kind).
Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...). Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...).
Returns(http.StatusOK, "OK", versionedObject).
Writes(versionedObject) Writes(versionedObject)
if isGetterWithOptions { if isGetterWithOptions {
if err := addObjectParams(ws, route, getOptions); err != nil { if err := addObjectParams(ws, route, getOptions); err != nil {
...@@ -350,9 +357,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag ...@@ -350,9 +357,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
case "LIST": // List all resources of a kind. case "LIST": // List all resources of a kind.
route := ws.GET(action.Path).To(ListResource(lister, watcher, reqScope, false)). route := ws.GET(action.Path).To(ListResource(lister, watcher, reqScope, false)).
Filter(m). Filter(m).
Doc("list objects of kind " + kind). Doc("list objects of kind "+kind).
Operation("list" + kind). Operation("list"+kind).
Produces("application/json"). Produces("application/json").
Returns(http.StatusOK, "OK", versionedList).
Writes(versionedList) Writes(versionedList)
if err := addObjectParams(ws, route, versionedListOptions); err != nil { if err := addObjectParams(ws, route, versionedListOptions); err != nil {
return err return err
...@@ -368,10 +376,12 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag ...@@ -368,10 +376,12 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
case "PUT": // Update a resource. case "PUT": // Update a resource.
route := ws.PUT(action.Path).To(UpdateResource(updater, reqScope, a.group.Typer, admit)). route := ws.PUT(action.Path).To(UpdateResource(updater, reqScope, a.group.Typer, admit)).
Filter(m). Filter(m).
Doc("replace the specified " + kind). Doc("replace the specified "+kind).
Operation("replace" + kind). Operation("replace"+kind).
Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...). Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...).
Reads(versionedObject) Returns(http.StatusOK, "OK", versionedObject).
Reads(versionedObject).
Writes(versionedObject)
addParams(route, action.Params) addParams(route, action.Params)
ws.Route(route) ws.Route(route)
case "PATCH": // Partially update a resource case "PATCH": // Partially update a resource
...@@ -379,26 +389,32 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag ...@@ -379,26 +389,32 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Filter(m). Filter(m).
Doc("partially update the specified "+kind). Doc("partially update the specified "+kind).
Consumes(string(api.JSONPatchType), string(api.MergePatchType), string(api.StrategicMergePatchType)). Consumes(string(api.JSONPatchType), string(api.MergePatchType), string(api.StrategicMergePatchType)).
Operation("patch" + kind). Operation("patch"+kind).
Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...). Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...).
Reads(versionedObject) Returns(http.StatusOK, "OK", "string").
Reads("string").
Writes(versionedObject)
addParams(route, action.Params) addParams(route, action.Params)
ws.Route(route) ws.Route(route)
case "POST": // Create a resource. case "POST": // Create a resource.
route := ws.POST(action.Path).To(CreateResource(creater, reqScope, a.group.Typer, admit)). route := ws.POST(action.Path).To(CreateResource(creater, reqScope, a.group.Typer, admit)).
Filter(m). Filter(m).
Doc("create a " + kind). Doc("create a "+kind).
Operation("create" + kind). Operation("create"+kind).
Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...). Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...).
Reads(versionedObject) Returns(http.StatusOK, "OK", versionedObject).
Reads(versionedObject).
Writes(versionedObject)
addParams(route, action.Params) addParams(route, action.Params)
ws.Route(route) ws.Route(route)
case "DELETE": // Delete a resource. case "DELETE": // Delete a resource.
route := ws.DELETE(action.Path).To(DeleteResource(gracefulDeleter, isGracefulDeleter, reqScope, admit)). route := ws.DELETE(action.Path).To(DeleteResource(gracefulDeleter, isGracefulDeleter, reqScope, admit)).
Filter(m). Filter(m).
Doc("delete a " + kind). Doc("delete a "+kind).
Operation("delete" + kind). Operation("delete"+kind).
Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...) Produces(append(storageMeta.ProducesMIMETypes(action.Verb), "application/json")...).
Writes(versionedStatus).
Returns(http.StatusOK, "OK", versionedStatus)
if isGracefulDeleter { if isGracefulDeleter {
route.Reads(versionedDeleterObject) route.Reads(versionedDeleterObject)
} }
...@@ -408,9 +424,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag ...@@ -408,9 +424,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
case "WATCH": // Watch a resource. case "WATCH": // Watch a resource.
route := ws.GET(action.Path).To(ListResource(lister, watcher, reqScope, true)). route := ws.GET(action.Path).To(ListResource(lister, watcher, reqScope, true)).
Filter(m). Filter(m).
Doc("watch changes to an object of kind " + kind). Doc("watch changes to an object of kind "+kind).
Operation("watch" + kind). Operation("watch"+kind).
Produces("application/json"). Produces("application/json").
Returns(http.StatusOK, "OK", watchjson.WatchEvent{}).
Writes(watchjson.WatchEvent{}) Writes(watchjson.WatchEvent{})
if err := addObjectParams(ws, route, versionedListOptions); err != nil { if err := addObjectParams(ws, route, versionedListOptions); err != nil {
return err return err
...@@ -421,9 +438,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag ...@@ -421,9 +438,10 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
case "WATCHLIST": // Watch all resources of a kind. case "WATCHLIST": // Watch all resources of a kind.
route := ws.GET(action.Path).To(ListResource(lister, watcher, reqScope, true)). route := ws.GET(action.Path).To(ListResource(lister, watcher, reqScope, true)).
Filter(m). Filter(m).
Doc("watch individual changes to a list of " + kind). Doc("watch individual changes to a list of "+kind).
Operation("watch" + kind + "list"). Operation("watch"+kind+"list").
Produces("application/json"). Produces("application/json").
Returns(http.StatusOK, "OK", watchjson.WatchEvent{}).
Writes(watchjson.WatchEvent{}) Writes(watchjson.WatchEvent{})
if err := addObjectParams(ws, route, versionedListOptions); err != nil { if err := addObjectParams(ws, route, versionedListOptions); err != nil {
return err return err
...@@ -436,7 +454,8 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag ...@@ -436,7 +454,8 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
Doc("redirect GET request to " + kind). Doc("redirect GET request to " + kind).
Operation("redirect" + kind). Operation("redirect" + kind).
Produces("*/*"). Produces("*/*").
Consumes("*/*") Consumes("*/*").
Writes("string")
addParams(route, action.Params) addParams(route, action.Params)
ws.Route(route) ws.Route(route)
case "PROXY": // Proxy requests to a resource. case "PROXY": // Proxy requests to a resource.
...@@ -694,7 +713,8 @@ func addProxyRoute(ws *restful.WebService, method string, prefix string, path st ...@@ -694,7 +713,8 @@ func addProxyRoute(ws *restful.WebService, method string, prefix string, path st
Doc("proxy " + method + " requests to " + kind). Doc("proxy " + method + " requests to " + kind).
Operation("proxy" + method + kind). Operation("proxy" + method + kind).
Produces("*/*"). Produces("*/*").
Consumes("*/*") Consumes("*/*").
Writes("string")
addParams(proxyRoute, params) addParams(proxyRoute, params)
ws.Route(proxyRoute) ws.Route(proxyRoute)
} }
...@@ -711,7 +731,7 @@ func addParams(route *restful.RouteBuilder, params []*restful.Parameter) { ...@@ -711,7 +731,7 @@ func addParams(route *restful.RouteBuilder, params []*restful.Parameter) {
// Go JSON behavior for omitting a field) become query parameters. The name of the query parameter is // Go JSON behavior for omitting a field) become query parameters. The name of the query parameter is
// the JSON field name. If a description struct tag is set on the field, that description is used on the // the JSON field name. If a description struct tag is set on the field, that description is used on the
// query parameter. In essence, it converts a standard JSON top level object into a query param schema. // query parameter. In essence, it converts a standard JSON top level object into a query param schema.
func addObjectParams(ws *restful.WebService, route *restful.RouteBuilder, obj runtime.Object) error { func addObjectParams(ws *restful.WebService, route *restful.RouteBuilder, obj interface{}) error {
sv, err := conversion.EnforcePtr(obj) sv, err := conversion.EnforcePtr(obj)
if err != nil { if err != nil {
return err return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment