// JSONAPIRelationshipLinks implements the RelationshipLinkable interface for a blog
4037
func (blog Blog) JSONAPIRelationshipLinks(relation string) *jsonapi.Links {
	if relation == "posts" {
		return &jsonapi.Links{
			"related": fmt.Sprintf("https://example.com/blogs/%d/posts", blog.ID),
		}
	}
	if relation == "current_post" {
		return &jsonapi.Links{
			"related": fmt.Sprintf("https://example.com/blogs/%d/current_post", blog.ID),
		}
	}
	return nil
}
926378
func (i *Client) postJSON(c context.Context, resource string, headers map[string]string, in, out interface{}) error {
	if len(resource) == 0 || resource[0] != '/' {
		return errors.New("resource must start with '/'")
	}
	_, err := lhttp.PostJSON(c, i.retryFactory, i.authClient, i.url+resource, headers, in, out)
	return err
}
1246770
func ErrorToJSONAPIError(ctx context.Context, err error) (app.JSONAPIError, int) {
	cause := errs.Cause(err)
	detail := cause.Error()
	var title, code string
	var statusCode int
	var id *string
	log.Error(ctx, map[string]interface{}{"err": cause, "error_message": cause.Error(), "err_type": reflect.TypeOf(cause)}, "an error occurred in our api")
	switch cause.(type) {
	case errors.NotFoundError:
		code = ErrorCodeNotFound
		title = "Not found error"
		statusCode = http.StatusNotFound
	case errors.ConversionError:
		code = ErrorCodeConversionError
		title = "Conversion error"
		statusCode = http.StatusBadRequest
	case errors.BadParameterError:
		code = ErrorCodeBadParameter
		title = "Bad parameter error"
		statusCode = http.StatusBadRequest
	case errors.VersionConflictError:
		code = ErrorCodeVersionConflict
		title = "Version conflict error"
		statusCode = http.StatusConflict
	case errors.DataConflictError:
		code = ErrorCodeDataConflict
		title = "Data conflict error"
		statusCode = http.StatusConflict
	case errors.InternalError:
		code = ErrorCodeInternalError
		title = "Internal error"
		statusCode = http.StatusInternalServerError
	case errors.UnauthorizedError:
		code = ErrorCodeUnauthorizedError
		title = "Unauthorized error"
		statusCode = http.StatusUnauthorized
	case errors.ForbiddenError:
		code = ErrorCodeForbiddenError
		title = "Forbidden error"
		statusCode = http.StatusForbidden
	default:
		code = ErrorCodeUnknownError
		title = "Unknown error"
		statusCode = http.StatusInternalServerError

		cause := errs.Cause(err)
		if err, ok := cause.(goa.ServiceError); ok {
			statusCode = err.ResponseStatus()
			idStr := err.Token()
			id = &idStr
			title = http.StatusText(statusCode)
		}
		if errResp, ok := cause.(*goa.ErrorResponse); ok {
			code = errResp.Code
			detail = errResp.Detail
		}
	}
	statusCodeStr := strconv.Itoa(statusCode)
	jerr := app.JSONAPIError{
		ID:     id,
		Code:   &code,
		Status: &statusCodeStr,
		Title:  &title,
		Detail: detail,
	}
	return jerr, statusCode
}
1174052
func (l Link) MarshalJSON() ([]byte, error) {
	if l.Empty() {
		return json.Marshal(nil)
	}
	if len(l.Meta) == 0 {
		return json.Marshal(l.Href)
	}
	return json.Marshal(map[string]interface{}{
		"href": l.Href,
		"meta": l.Meta,
	})
}
461090
func (u *GetSharedLinksResult) UnmarshalJSON(b []byte) error {
	type wrap struct {
		// Links : Shared links applicable to the path argument.
		Links []json.RawMessage `json:"links"`
	}
	var w wrap
	if err := json.Unmarshal(b, &w); err != nil {
		return err
	}
	u.Links = make([]IsLinkMetadata, len(w.Links))
	for i, e := range w.Links {
		v, err := IsLinkMetadataFromJSON(e)
		if err != nil {
			return err
		}
		u.Links[i] = v
	}
	return nil
}
855539
func (c *Client) ListAPIKeys(opts ...interface{}) (res ListAPIKeysRes, err error) {
	path := c.path("/keys")
	err = c.transport.Request(&res, http.MethodGet, path, nil, call.Read, opts...)
	return
}
765310
func ConvertLinkFromModel(request *http.Request, t link.WorkItemLink) app.WorkItemLinkSingle {
	linkSelfURL := rest.AbsoluteURL(request, app.WorkItemLinkHref(t.ID.String()))
	linkTypeRelatedURL := rest.AbsoluteURL(request, app.WorkItemLinkTypeHref(t.LinkTypeID.String()))

	sourceRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref(t.SourceID.String()))
	targetRelatedURL := rest.AbsoluteURL(request, app.WorkitemHref(t.TargetID.String()))

	var converted = app.WorkItemLinkSingle{
		Data: &app.WorkItemLinkData{
			Type: link.EndpointWorkItemLinks,
			ID:   &t.ID,
			Attributes: &app.WorkItemLinkAttributes{
				CreatedAt: &t.CreatedAt,
				UpdatedAt: &t.UpdatedAt,
				Version:   &t.Version,
			},
			Links: &app.GenericLinks{
				Self: &linkSelfURL,
			},
			Relationships: &app.WorkItemLinkRelationships{
				LinkType: &app.RelationWorkItemLinkType{
					Data: &app.RelationWorkItemLinkTypeData{
						Type: link.EndpointWorkItemLinkTypes,
						ID:   t.LinkTypeID,
					},
					Links: &app.GenericLinks{
						Self: &linkTypeRelatedURL,
					},
				},
				Source: &app.RelationWorkItem{
					Data: &app.RelationWorkItemData{
						Type: link.EndpointWorkItems,
						ID:   t.SourceID,
					},
					Links: &app.GenericLinks{
						Related: &sourceRelatedURL,
					},
				},
				Target: &app.RelationWorkItem{
					Data: &app.RelationWorkItemData{
						Type: link.EndpointWorkItems,
						ID:   t.TargetID,
					},
					Links: &app.GenericLinks{
						Related: &targetRelatedURL,
					},
				},
			},
		},
	}
	return converted
}
1315438
func (fw *Framework) NewReplyFromTransportJSON(payload []byte, skipvalidate bool) (msg protocol.Reply, err error) {
	transport, err := fw.NewTransportFromJSON(string(payload))
	if err != nil {
		return nil, err
	}

	sreply, err := fw.NewSecureReplyFromTransport(transport, skipvalidate)
	if err != nil {
		return nil, err
	}

	reply, err := fw.NewReplyFromSecureReply(sreply)
	if err != nil {
		return nil, err
	}

	protocol.CopyFederationData(transport, reply)

	return reply, nil
}
91373
func (u *AppUnlinkTeamDetails) UnmarshalJSON(b []byte) error {
	type wrap struct {
		// AppInfo : Relevant application details.
		AppInfo json.RawMessage `json:"app_info"`
	}
	var w wrap
	if err := json.Unmarshal(b, &w); err != nil {
		return err
	}
	AppInfo, err := IsAppLogInfoFromJSON(w.AppInfo)
	if err != nil {
		return err
	}
	u.AppInfo = AppInfo
	return nil
}
32079
func jsonProperties(f reflect.StructField, origName bool) *proto.Properties {
	var prop proto.Properties
	prop.Init(f.Type, f.Name, f.Tag.Get("protobuf"), &f)
	if origName || prop.JSONName == "" {
		prop.JSONName = prop.OrigName
	}
	return &prop
}
1038468
func LinkSetAlias(link Link, name string) error {
	return pkgHandle.LinkSetAlias(link, name)
}
1297041
func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *APIGroupInfo, openAPIModels openapiproto.Models) error {
	for _, groupVersion := range apiGroupInfo.PrioritizedVersions {
		if len(apiGroupInfo.VersionedResourcesStorageMap[groupVersion.Version]) == 0 {
			klog.Warningf("Skipping API %v because it has no resources.", groupVersion)
			continue
		}

		apiGroupVersion := s.getAPIGroupVersion(apiGroupInfo, groupVersion, apiPrefix)
		if apiGroupInfo.OptionsExternalVersion != nil {
			apiGroupVersion.OptionsExternalVersion = apiGroupInfo.OptionsExternalVersion
		}
		apiGroupVersion.OpenAPIModels = openAPIModels
		apiGroupVersion.MaxRequestBodyBytes = s.maxRequestBodyBytes

		if err := apiGroupVersion.InstallREST(s.Handler.GoRestfulContainer); err != nil {
			return fmt.Errorf("unable to setup API %v: %v", apiGroupInfo, err)
		}
	}

	return nil
}
505870
func (api *RemoteRelationsAPI) ExportEntities(entities params.Entities) (params.TokenResults, error) {
	results := params.TokenResults{
		Results: make([]params.TokenResult, len(entities.Entities)),
	}
	for i, entity := range entities.Entities {
		tag, err := names.ParseTag(entity.Tag)
		if err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
		token, err := api.st.ExportLocalEntity(tag)
		if err != nil {
			results.Results[i].Error = common.ServerError(err)
			if !errors.IsAlreadyExists(err) {
				continue
			}
		}
		results.Results[i].Token = token
	}
	return results, nil
}
1355127
func (b *BuilderSummary) SelfLink() string {
	if b == nil {
		return InvalidBuilderIDURL
	}
	return BuilderIDLink(b.BuilderID, b.ProjectID)
}
1095443
func (a *InternalAPIEngine) PostJSON(m MetaContext, arg APIArg) (*APIRes, error) {
	return a.Post(m, arg)
}
945737
func (a *APIAddresser) APIHostPorts() (params.APIHostPortsResult, error) {
	servers, err := a.getter.APIHostPortsForAgents()
	if err != nil {
		return params.APIHostPortsResult{}, err
	}
	return params.APIHostPortsResult{
		Servers: params.FromNetworkHostsPorts(servers),
	}, nil
}
285983
func (l Links) HrefParams(rel string, params P) (string, error) {
	if rel == "" {
		return "", errors.New("Empty string not valid relation")
	}

	links := l.Items[rel]
	if len(links) > 0 {
		link := links[0] // TODO: handle multiple here
		return link.Expand(params)
	}

	return "", LinkNotFoundError{rel, l.Items}
}