コード例 #1
0
ファイル: validation.go プロジェクト: intfrr/goa
// Validate checks that the user type definition is consistent: it has a name and all user and media
// types used in fields support the API versions that use the type.
func (u *UserTypeDefinition) Validate(ctx string, parent dslengine.Definition) *dslengine.ValidationErrors {
	verr := new(dslengine.ValidationErrors)
	if u.TypeName == "" {
		verr.Add(parent, "%s - %s", ctx, "User type must have a name")
	}
	if u.Type != nil {
		// u.Type can be nil when types refer to each other.
		if o := u.ToObject(); o != nil {
			o.IterateAttributes(func(name string, at *AttributeDefinition) error {
				var ut *UserTypeDefinition
				if mt, ok := at.Type.(*MediaTypeDefinition); ok {
					ut = mt.UserTypeDefinition
				} else if ut2, ok := at.Type.(*UserTypeDefinition); ok {
					ut = ut2
				}
				if ut != nil {
					if err := dslengine.CanUse(u, ut); err != nil {
						verr.Add(u, err.Error())
					}
				}
				return nil
			})
		}
	}
	verr.Merge(u.AttributeDefinition.Validate(ctx, parent))
	return verr.AsError()
}
コード例 #2
0
ファイル: validation.go プロジェクト: intfrr/goa
// Validate tests whether the resource definition is consistent: action names are valid and each action is
// valid.
func (r *ResourceDefinition) Validate(version *APIVersionDefinition) *dslengine.ValidationErrors {
	verr := new(dslengine.ValidationErrors)
	if r.Name == "" {
		verr.Add(r, "Resource name cannot be empty")
	}
	r.validateActions(version, verr)
	if r.BaseParams != nil {
		r.validateBaseParams(verr)
	}
	if r.ParentName != "" {
		r.validateParent(verr)
	}
	for _, resp := range r.Responses {
		verr.Merge(resp.Validate())
	}
	if r.Params != nil {
		verr.Merge(r.Params.Validate("resource parameters", r))
	}
	if !r.SupportsNoVersion() {
		if err := dslengine.CanUse(r, Design); err != nil {
			verr.Add(r, "Invalid API version in list")
		}
	}
	return verr.AsError()
}
コード例 #3
0
ファイル: validation.go プロジェクト: intfrr/goa
func (r *ResourceDefinition) validateParent(verr *dslengine.ValidationErrors) {
	p, ok := Design.Resources[r.ParentName]
	if !ok {
		verr.Add(r, "Parent resource named %#v not found", r.ParentName)
	} else {
		if p.CanonicalAction() == nil {
			verr.Add(r, "Parent resource %#v has no canonical action", r.ParentName)
		}
		if err := dslengine.CanUse(r, p); err != nil {
			verr.Add(r, err.Error())
		}
	}
}