diff --git a/vendor/github.com/rancher/norman/pkg/api/writer/json.go b/vendor/github.com/rancher/norman/pkg/api/writer/json.go index 98ecb64..068ab49 100644 --- a/vendor/github.com/rancher/norman/pkg/api/writer/json.go +++ b/vendor/github.com/rancher/norman/pkg/api/writer/json.go @@ -4,11 +4,13 @@ import ( "fmt" "io" "net/http" + "reflect" "github.com/rancher/norman/pkg/data" "github.com/rancher/norman/pkg/parse" "github.com/rancher/norman/pkg/parse/builder" "github.com/rancher/norman/pkg/types" + "github.com/rancher/norman/pkg/types/convert" "github.com/rancher/norman/pkg/types/definition" "github.com/sirupsen/logrus" ) @@ -60,7 +62,15 @@ func (j *EncodingResponseWriter) VersionBody(apiOp *types.APIRequest, writer io. case types.RawResource: output = v default: - output = v + mapData, err := convert.EncodeToMap(obj) + if err != nil { + return err + } + schema := apiOp.Schemas.SchemaFor(reflect.TypeOf(obj)) + if schema != nil && mapData != nil { + mapData["type"] = schema.ID + } + output = j.convert(builder, apiOp, mapData) } if list, ok := output.(*types.GenericCollection); ok && revision != "" { diff --git a/vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go b/vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go index affd4fc..ab722d1 100644 --- a/vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go +++ b/vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go @@ -199,8 +199,9 @@ func (s *Store) toAPIEvent(apiOp *types.APIRequest, schema *types.Schema, et wat s.fromInternal(apiOp, schema, obj.Object) return types.APIEvent{ - Name: name, - Object: types.ToAPI(obj.Object), + Name: name, + Revision: obj.GetResourceVersion(), + Object: types.ToAPI(obj.Object), } } diff --git a/vendor/github.com/rancher/norman/pkg/types/reflection.go b/vendor/github.com/rancher/norman/pkg/types/reflection.go index 78d3c88..eb74fdd 100644 --- a/vendor/github.com/rancher/norman/pkg/types/reflection.go +++ b/vendor/github.com/rancher/norman/pkg/types/reflection.go @@ -33,6 +33,11 @@ func (s *Schemas) getTypeName(t reflect.Type) string { return convert.LowerTitle(t.Name()) } +func (s *Schemas) SchemaFor(t reflect.Type) *Schema { + name := s.getTypeName(t) + return s.Schema(name) +} + func (s *Schemas) AddMapperForType(obj interface{}, mapper ...Mapper) *Schemas { if len(mapper) == 0 { return s @@ -79,6 +84,7 @@ func (s *Schemas) newSchemaFromType(t reflect.Type, typeName string) (*Schema, e ResourceFields: map[string]Field{}, ResourceActions: map[string]Action{}, CollectionActions: map[string]Action{}, + Attributes: map[string]interface{}{}, } s.processingTypes[t] = schema diff --git a/vendor/github.com/rancher/norman/pkg/types/server_types.go b/vendor/github.com/rancher/norman/pkg/types/server_types.go index 9b5e8e4..3790e56 100644 --- a/vendor/github.com/rancher/norman/pkg/types/server_types.go +++ b/vendor/github.com/rancher/norman/pkg/types/server_types.go @@ -211,6 +211,7 @@ type WatchRequest struct { type APIEvent struct { Name string `json:"name,omitempty"` ResourceType string `json:"resourceType,omitempty"` + Revision string `json:"revision,omitempty"` Object APIObject `json:"-"` Error error `json:"-"` // Data should be used @@ -247,7 +248,8 @@ func (a APIObject) IsNil() bool { if a.Object == nil { return true } - return reflect.ValueOf(a.Object).IsNil() + val := reflect.ValueOf(a.Object) + return val.Kind() == reflect.Ptr && val.IsNil() } func (a *APIObject) List() data.List {