Action-Schema JSON validation

charm.ActionSpec now has a ValidateParams method which accepts an
unmarshaled JSON document, and validates it.  If it is valid, the
method returns true; otherwise, it returns false and a list of
errors returned by gojsonschema.

WIP, opened PR for comments
On Thu, Jun 12, 2014 at 11:38 AM, Bodie Solomon <notifications@github.com>
wrote:

> In actions.go:
>
> > @@ -35,6 +36,29 @@ func NewActions() *Actions {
> >  	return &Actions{}
> >  }
> >
> > +// ValidateParams tells us whether an unmarshaled JSON object conforms to the
> > +// Params for the specific ActionSpec.
> > +//
> > +// Usage: ok, err := ch.Actions()["snapshot"].Validate(jsonParams)
> > +func (spec *ActionSpec) ValidateParams(paramsMap interface{}) (bool, error) {
> > +
> > +	specSchemaDoc, err := gojsonschema.NewJsonSchemaDocument(spec.Params)
> > +	if err != nil {
> > +		return false, err
> > +	}
> > +
> > +	results := specSchemaDoc.Validate(paramsMap)
> > +	if !results.Valid() {
> > +		var errorStrings []string
> > +		for _, validationError := range results.Errors() {
>
> Unfortunately, Errors() returns a custom type for gojsonschema,
> ValidationError.
>
> http://godoc.org/github.com/binary132/gojsonschema#ValidationResult.Errors
>
> ValidationError itself has a String() method.
>
Yuk. Let's fix gojsonschema to return proper `error` types.


> —
> Reply to this email directly or view it on GitHub
> <https://github.com/juju/charm/pull/4/files#r13684210>.
>