// NewLink creates an object of type Link if possible, returning an error if not.
439061
func NewLink(in interface{}, context *compiler.Context) (*Link, error) {
	errors := make([]error, 0)
	x := &Link{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		allowedKeys := []string{"description", "operationId", "operationRef", "parameters", "requestBody", "server"}
		allowedPatterns := []*regexp.Regexp{pattern1}
		invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns)
		if len(invalidKeys) > 0 {
			message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", "))
			errors = append(errors, compiler.NewError(context, message))
		}
		// string operation_ref = 1;
		v1 := compiler.MapValueForKey(m, "operationRef")
		if v1 != nil {
			x.OperationRef, ok = v1.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for operationRef: %+v (%T)", v1, v1)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// string operation_id = 2;
		v2 := compiler.MapValueForKey(m, "operationId")
		if v2 != nil {
			x.OperationId, ok = v2.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for operationId: %+v (%T)", v2, v2)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// AnysOrExpressions parameters = 3;
		v3 := compiler.MapValueForKey(m, "parameters")
		if v3 != nil {
			var err error
			x.Parameters, err = NewAnysOrExpressions(v3, compiler.NewContext("parameters", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// AnyOrExpression request_body = 4;
		v4 := compiler.MapValueForKey(m, "requestBody")
		if v4 != nil {
			var err error
			x.RequestBody, err = NewAnyOrExpression(v4, compiler.NewContext("requestBody", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// string description = 5;
		v5 := compiler.MapValueForKey(m, "description")
		if v5 != nil {
			x.Description, ok = v5.(string)
			if !ok {
				message := fmt.Sprintf("has unexpected value for description: %+v (%T)", v5, v5)
				errors = append(errors, compiler.NewError(context, message))
			}
		}
		// Server server = 6;
		v6 := compiler.MapValueForKey(m, "server")
		if v6 != nil {
			var err error
			x.Server, err = NewServer(v6, compiler.NewContext("server", context))
			if err != nil {
				errors = append(errors, err)
			}
		}
		// repeated NamedAny specification_extension = 7;
		// MAP: Any ^x-
		x.SpecificationExtension = make([]*NamedAny, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				if strings.HasPrefix(k, "x-") {
					pair := &NamedAny{}
					pair.Name = k
					result := &Any{}
					handled, resultFromExt, err := compiler.HandleExtension(context, v, k)
					if handled {
						if err != nil {
							errors = append(errors, err)
						} else {
							bytes, _ := yaml.Marshal(v)
							result.Yaml = string(bytes)
							result.Value = resultFromExt
							pair.Value = result
						}
					} else {
						pair.Value, err = NewAny(v, compiler.NewContext(k, context))
						if err != nil {
							errors = append(errors, err)
						}
					}
					x.SpecificationExtension = append(x.SpecificationExtension, pair)
				}
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
282113
func NewLinkPermissions(CanRevoke bool) *LinkPermissions {
	s := new(LinkPermissions)
	s.CanRevoke = CanRevoke
	return s
}
500147
func (db *DB) NewLinkNode(bitNet wire.BitcoinNet, pub *btcec.PublicKey,
	addrs ...net.Addr) *LinkNode {

	return &LinkNode{
		Network:     bitNet,
		IdentityPub: pub,
		LastSeen:    time.Now(),
		Addresses:   addrs,
		db:          db,
	}
}
681029
func NewFolderLinkMetadata(Url string, Name string, LinkPermissions *LinkPermissions) *FolderLinkMetadata {
	s := new(FolderLinkMetadata)
	s.Url = Url
	s.Name = Name
	s.LinkPermissions = LinkPermissions
	return s
}
299097
func (c ConstantString) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
	// TODO(abg): Are binary literals a thing?
	if _, ok := RootTypeSpec(t).(*StringSpec); !ok {
		return nil, constantValueCastError{Value: c, Type: t}
	}
	return c, nil
}
1244807
func (rs *ResultSpec) Link(scope Scope) (err error) {
	if rs.ReturnType != nil {
		rs.ReturnType, err = rs.ReturnType.Link(scope)
		if err != nil {
			return err
		}
	}

	if err := rs.Exceptions.Link(scope); err != nil {
		return err
	}

	// verify that everything listed under throws is an exception.
	for _, exception := range rs.Exceptions {
		spec, ok := exception.Type.(*StructSpec)
		if !ok || spec.Type != ast.ExceptionType {
			return notAnExceptionError{
				FieldName: exception.ThriftName(),
				TypeName:  spec.ThriftName(),
			}
		}
	}

	return nil
}
851503
func NewLinkNotFound(msg string, a ...interface{}) LinkNotFound {
	msg = fmt.Sprintf("Link Not Found: "+msg, a...)
	return LinkNotFound{
		error: errors.New(msg),
	}
}
237982
func (a *Artist) Link() *Link {
	sp_link := C.sp_link_create_from_artist(a.sp_artist)
	return newLink(a.session, sp_link, false)
}
1243314
func NewLinkOrReference(in interface{}, context *compiler.Context) (*LinkOrReference, error) {
	errors := make([]error, 0)
	x := &LinkOrReference{}
	matched := false
	// Link link = 1;
	{
		m, ok := compiler.UnpackMap(in)
		if ok {
			// errors might be ok here, they mean we just don't have the right subtype
			t, matchingError := NewLink(m, compiler.NewContext("link", context))
			if matchingError == nil {
				x.Oneof = &LinkOrReference_Link{Link: t}
				matched = true
			} else {
				errors = append(errors, matchingError)
			}
		}
	}
	// Reference reference = 2;
	{
		m, ok := compiler.UnpackMap(in)
		if ok {
			// errors might be ok here, they mean we just don't have the right subtype
			t, matchingError := NewReference(m, compiler.NewContext("reference", context))
			if matchingError == nil {
				x.Oneof = &LinkOrReference_Reference{Reference: t}
				matched = true
			} else {
				errors = append(errors, matchingError)
			}
		}
	}
	if matched {
		// since the oneof matched one of its possibilities, discard any matching errors
		errors = make([]error, 0)
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
205769
func NewDeviceLinkFailType(Description string) *DeviceLinkFailType {
	s := new(DeviceLinkFailType)
	s.Description = Description
	return s
}
564116
func (c Client) New(params *stripe.AccountLinkParams) (*stripe.AccountLink, error) {
	link := &stripe.AccountLink{}
	err := c.B.Call(http.MethodPost, "/v1/account_links", c.Key, params, link)
	return link, err
}
482814
func (m *MapSpec) Link(scope Scope) (TypeSpec, error) {
	if m.linked() {
		return m, nil
	}

	var err error
	m.KeySpec, err = m.KeySpec.Link(scope)
	if err != nil {
		return m, err
	}

	m.ValueSpec, err = m.ValueSpec.Link(scope)
	if err != nil {
		return m, err
	}

	return m, nil
}
231744
func (r *Resource) AddNewLink(rel Relation, href string) {
	r.AddLink(rel, NewLink(href, nil))
}
596929
func NewLinkFrom(ifcName string) (Linker, error) {
	if ok, err := NetInterfaceNameValid(ifcName); !ok {
		return nil, err
	}

	newIfc, err := net.InterfaceByName(ifcName)
	if err != nil {
		return nil, fmt.Errorf("Could not find the new interface: %s", err)
	}

	return &Link{
		ifc: newIfc,
	}, nil
}
1355127
func (b *BuilderSummary) SelfLink() string {
	if b == nil {
		return InvalidBuilderIDURL
	}
	return BuilderIDLink(b.BuilderID, b.ProjectID)
}
1200685
func NewAppLinkUserType(Description string) *AppLinkUserType {
	s := new(AppLinkUserType)
	s.Description = Description
	return s
}
720588
func (e EnumItemReference) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
	if RootTypeSpec(t) != e.Enum {
		return nil, constantValueCastError{Value: e, Type: t}
	}
	return e, nil
}