diff --git a/api/writer/json.go b/api/writer/json.go index accf5e46..c3a5ccff 100644 --- a/api/writer/json.go +++ b/api/writer/json.go @@ -80,6 +80,11 @@ func (j *JSONResponseWriter) writeInterfaceSlice(builder *builder.Builder, apiCo collection.Data = append(collection.Data, v) } } + + if apiContext.Schema.CollectionFormatter != nil { + apiContext.Schema.CollectionFormatter(apiContext, collection) + } + return collection } diff --git a/types/server_types.go b/types/server_types.go index ccbe607d..dd2a0c24 100644 --- a/types/server_types.go +++ b/types/server_types.go @@ -55,6 +55,8 @@ type Validator func(request *APIContext, schema *Schema, data map[string]interfa type Formatter func(request *APIContext, resource *RawResource) +type CollectionFormatter func(request *APIContext, collection *GenericCollection) + type ErrorHandler func(request *APIContext, err error) type SubContextAttributeProvider interface { diff --git a/types/types.go b/types/types.go index f4601938..79b7c6ba 100644 --- a/types/types.go +++ b/types/types.go @@ -103,18 +103,19 @@ type Schema struct { CollectionFilters map[string]Filter `json:"collectionFilters,omitempty"` Scope TypeScope `json:"-"` - InternalSchema *Schema `json:"-"` - Mapper Mapper `json:"-"` - ActionHandler ActionHandler `json:"-"` - LinkHandler RequestHandler `json:"-"` - ListHandler RequestHandler `json:"-"` - CreateHandler RequestHandler `json:"-"` - DeleteHandler RequestHandler `json:"-"` - UpdateHandler RequestHandler `json:"-"` - Formatter Formatter `json:"-"` - ErrorHandler ErrorHandler `json:"-"` - Validator Validator `json:"-"` - Store Store `json:"-"` + InternalSchema *Schema `json:"-"` + Mapper Mapper `json:"-"` + ActionHandler ActionHandler `json:"-"` + LinkHandler RequestHandler `json:"-"` + ListHandler RequestHandler `json:"-"` + CreateHandler RequestHandler `json:"-"` + DeleteHandler RequestHandler `json:"-"` + UpdateHandler RequestHandler `json:"-"` + Formatter Formatter `json:"-"` + CollectionFormatter CollectionFormatter `json:"-"` + ErrorHandler ErrorHandler `json:"-"` + Validator Validator `json:"-"` + Store Store `json:"-"` } type Field struct {