mirror of
https://github.com/rancher/norman.git
synced 2025-09-02 07:44:51 +00:00
Subcontext and mapping updates
This commit is contained in:
26
api/handler/validate.go
Normal file
26
api/handler/validate.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/rancher/norman/parse"
|
||||
"github.com/rancher/norman/parse/builder"
|
||||
"github.com/rancher/norman/types"
|
||||
)
|
||||
|
||||
func ParseAndValidateBody(apiContext *types.APIContext) (map[string]interface{}, error) {
|
||||
data, err := parse.Body(apiContext.Request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b := builder.NewBuilder(apiContext)
|
||||
|
||||
data, err = b.Construct(apiContext.Schema, data, builder.Create)
|
||||
validator := apiContext.Schema.Validator
|
||||
if validator != nil {
|
||||
if err := validator(apiContext, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
Reference in New Issue
Block a user