1
0
mirror of https://github.com/rancher/norman.git synced 2025-08-04 17:09:58 +00:00

Add InputFormatter that runs before the builder/validation

This commit is contained in:
Darren Shepherd 2018-07-13 12:56:01 -07:00
parent 16ed673d50
commit f33accee7c
3 changed files with 9 additions and 0 deletions

View File

@ -27,6 +27,12 @@ func ParseAndValidateBody(apiContext *types.APIContext, create bool) (map[string
if !create { if !create {
op = builder.Update 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) data, err = b.Construct(apiContext.Schema, data, op)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -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 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 Formatter func(request *APIContext, resource *RawResource)
type CollectionFormatter func(request *APIContext, collection *GenericCollection) type CollectionFormatter func(request *APIContext, collection *GenericCollection)

View File

@ -111,6 +111,7 @@ type Schema struct {
CreateHandler RequestHandler `json:"-"` CreateHandler RequestHandler `json:"-"`
DeleteHandler RequestHandler `json:"-"` DeleteHandler RequestHandler `json:"-"`
UpdateHandler RequestHandler `json:"-"` UpdateHandler RequestHandler `json:"-"`
InputFormatter InputFormatter `json:"-"`
Formatter Formatter `json:"-"` Formatter Formatter `json:"-"`
CollectionFormatter CollectionFormatter `json:"-"` CollectionFormatter CollectionFormatter `json:"-"`
ErrorHandler ErrorHandler `json:"-"` ErrorHandler ErrorHandler `json:"-"`