diff --git a/api/handler/validate.go b/api/handler/validate.go index b08b642f4..629c548cf 100644 --- a/api/handler/validate.go +++ b/api/handler/validate.go @@ -34,3 +34,20 @@ func ParseAndValidateBody(apiContext *types.APIContext, create bool) (map[string return data, nil } + +func ParseAndValidateActionBody(apiContext *types.APIContext, actionInputSchema *types.Schema) (map[string]interface{}, error) { + data, err := parse.Body(apiContext.Request) + if err != nil { + return nil, err + } + + b := builder.NewBuilder(apiContext) + + op := builder.Create + data, err = b.Construct(actionInputSchema, data, op) + if err != nil { + return nil, err + } + + return data, nil +} diff --git a/parse/builder/builder.go b/parse/builder/builder.go index 0a1c81758..905ea9941 100644 --- a/parse/builder/builder.go +++ b/parse/builder/builder.go @@ -125,7 +125,7 @@ func (b *Builder) checkDefaultAndRequired(schema *types.Schema, input map[string } if definition.IsArrayType(field.Type) { - slice, err := b.convertArray(fieldName, result[fieldName], op) + slice, err := b.convertArray(field.Type, result[fieldName], op) if err != nil { return err } diff --git a/parse/parse.go b/parse/parse.go index 8525f89a9..b8720f280 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -281,7 +281,7 @@ func Body(req *http.Request) (map[string]interface{}, error) { return valuesToBody(req.MultipartForm.Value), nil } - if req.Form != nil && len(req.Form) > 0 { + if req.PostForm != nil && len(req.PostForm) > 0 { return valuesToBody(map[string][]string(req.Form)), nil }