diff --git a/api/handler/validate.go b/api/handler/validate.go index 629c548c..4619d9ce 100644 --- a/api/handler/validate.go +++ b/api/handler/validate.go @@ -27,6 +27,12 @@ func ParseAndValidateBody(apiContext *types.APIContext, create bool) (map[string if !create { op = builder.Update } + if apiContext.Schema.InputFormatter != nil { + err = apiContext.Schema.InputFormatter(apiContext, apiContext.Schema, data, create) + if err != nil { + return nil, err + } + } data, err = b.Construct(apiContext.Schema, data, op) if err != nil { return nil, err diff --git a/types/server_types.go b/types/server_types.go index cc39aeb9..7fede86f 100644 --- a/types/server_types.go +++ b/types/server_types.go @@ -69,6 +69,8 @@ type QueryFilter func(opts *QueryOptions, schema *Schema, data []map[string]inte type Validator func(request *APIContext, schema *Schema, data map[string]interface{}) error +type InputFormatter func(request *APIContext, schema *Schema, data map[string]interface{}, create bool) error + type Formatter func(request *APIContext, resource *RawResource) type CollectionFormatter func(request *APIContext, collection *GenericCollection) diff --git a/types/types.go b/types/types.go index 27f2917d..88dfad3e 100644 --- a/types/types.go +++ b/types/types.go @@ -111,6 +111,7 @@ type Schema struct { CreateHandler RequestHandler `json:"-"` DeleteHandler RequestHandler `json:"-"` UpdateHandler RequestHandler `json:"-"` + InputFormatter InputFormatter `json:"-"` Formatter Formatter `json:"-"` CollectionFormatter CollectionFormatter `json:"-"` ErrorHandler ErrorHandler `json:"-"`