Add DecodeIntoWithSpecifiedVersionKind() to Decoder interface.

The function validate/default the body with the passed in apiVersion and Kind.
It's called in createHandler and UpdateResource
This commit is contained in:
Chao Xu
2015-06-19 17:16:25 -07:00
parent c5bffaaf31
commit 664d20c572
8 changed files with 216 additions and 40 deletions

View File

@@ -302,7 +302,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
}
obj := r.New()
if err := scope.Codec.DecodeInto(body, obj); err != nil {
if err := scope.Codec.DecodeIntoWithSpecifiedVersionKind(body, obj, scope.APIVersion, scope.Kind); err != nil {
err = transformDecodeError(typer, err, obj, body)
errorJSON(err, scope.Codec, w)
return
@@ -469,7 +469,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectType
}
obj := r.New()
if err := scope.Codec.DecodeInto(body, obj); err != nil {
if err := scope.Codec.DecodeIntoWithSpecifiedVersionKind(body, obj, scope.APIVersion, scope.Kind); err != nil {
err = transformDecodeError(typer, err, obj, body)
errorJSON(err, scope.Codec, w)
return