mirror of
https://github.com/niusmallnan/steve.git
synced 2025-08-01 05:57:21 +00:00
Handle typed responses better
This commit is contained in:
parent
4016d67f8b
commit
73646d17ea
12
vendor/github.com/rancher/norman/pkg/api/writer/json.go
generated
vendored
12
vendor/github.com/rancher/norman/pkg/api/writer/json.go
generated
vendored
@ -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 != "" {
|
||||
|
5
vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go
generated
vendored
5
vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go
generated
vendored
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
6
vendor/github.com/rancher/norman/pkg/types/reflection.go
generated
vendored
6
vendor/github.com/rancher/norman/pkg/types/reflection.go
generated
vendored
@ -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
|
||||
|
4
vendor/github.com/rancher/norman/pkg/types/server_types.go
generated
vendored
4
vendor/github.com/rancher/norman/pkg/types/server_types.go
generated
vendored
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user