jsonapi

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package jsonapi provides JSON:API specification compliant types for API responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchData

type BranchData struct {
	Name        string `json:"name"`
	IsDefault   bool   `json:"is_default"`
	CommitCount int    `json:"commit_count"`
}

BranchData represents branch data for repository details.

type CommitAttributes

type CommitAttributes struct {
	CommitSHA       string    `json:"commit_sha"`
	Date            time.Time `json:"date"`
	Message         string    `json:"message"`
	ParentCommitSHA string    `json:"parent_commit_sha"`
	Author          string    `json:"author"`
}

CommitAttributes represents commit attributes in JSON:API format.

type DateTime

type DateTime time.Time

DateTime handles JSON serialization of time.Time to ISO8601 format.

func NewDateTime

func NewDateTime(t time.Time) DateTime

NewDateTime creates a DateTime from a time.Time.

func (DateTime) MarshalJSON

func (dt DateTime) MarshalJSON() ([]byte, error)

MarshalJSON serializes the DateTime to ISO8601 format.

func (DateTime) Ptr

func (dt DateTime) Ptr() *DateTime

Ptr returns a pointer to the DateTime.

func (DateTime) Time

func (dt DateTime) Time() time.Time

Time returns the underlying time.Time.

func (*DateTime) UnmarshalJSON

func (dt *DateTime) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes ISO8601 format to DateTime.

type Document

type Document struct {
	Data     any     `json:"data"`
	Meta     *Meta   `json:"meta,omitempty"`
	Links    *Links  `json:"links,omitempty"`
	Included []any   `json:"included,omitempty"`
	Errors   []Error `json:"errors,omitempty"`
}

Document represents a JSON:API top-level document. See: https://jsonapi.org/format/#document-structure

func NewErrorResponse

func NewErrorResponse(errors ...Error) *Document

NewErrorResponse creates a JSON:API document with errors.

func NewListResponse

func NewListResponse(resources []*Resource) *Document

NewListResponse creates a JSON:API document with a list of resources.

func NewSingleResponse

func NewSingleResponse(resource *Resource) *Document

NewSingleResponse creates a JSON:API document with a single resource.

type EnrichmentAttributes

type EnrichmentAttributes struct {
	Type      string     `json:"type"`
	Subtype   *string    `json:"subtype"`
	Content   string     `json:"content"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

EnrichmentAttributes represents enrichment attributes in JSON:API format.

type Error

type Error struct {
	ID     string       `json:"id,omitempty"`
	Links  *ErrorLinks  `json:"links,omitempty"`
	Status string       `json:"status,omitempty"`
	Code   string       `json:"code,omitempty"`
	Title  string       `json:"title,omitempty"`
	Detail string       `json:"detail,omitempty"`
	Source *ErrorSource `json:"source,omitempty"`
	Meta   *Meta        `json:"meta,omitempty"`
}

Error represents a JSON:API error object. See: https://jsonapi.org/format/#error-objects

func NewError

func NewError(status, title, detail string) Error

NewError creates a simple error with status, title and detail.

type ErrorLinks struct {
	About string `json:"about,omitempty"`
	Type  string `json:"type,omitempty"`
}

ErrorLinks holds links for error objects.

type ErrorSource

type ErrorSource struct {
	Pointer   string `json:"pointer,omitempty"`
	Parameter string `json:"parameter,omitempty"`
	Header    string `json:"header,omitempty"`
}

ErrorSource holds references to the source of an error.

type FileAttributes

type FileAttributes struct {
	BlobSHA   string `json:"blob_sha"`
	Path      string `json:"path"`
	MimeType  string `json:"mime_type"`
	Size      int64  `json:"size"`
	Extension string `json:"extension"`
}

FileAttributes represents file attributes in JSON:API format.

type Links struct {
	Self  string `json:"self,omitempty"`
	First string `json:"first,omitempty"`
	Last  string `json:"last,omitempty"`
	Prev  string `json:"prev,omitempty"`
	Next  string `json:"next,omitempty"`
}

Links holds links associated with a document or resource.

type Meta

type Meta map[string]any

Meta holds non-standard meta-information about a document.

type RecentCommitData

type RecentCommitData struct {
	SHA       string    `json:"sha"`
	Message   string    `json:"message"`
	Author    string    `json:"author"`
	Timestamp time.Time `json:"timestamp"`
}

RecentCommitData represents commit data for repository details.

type Relationship

type Relationship struct {
	Links *Links `json:"links,omitempty"`
	Data  any    `json:"data,omitempty"` // Can be ResourceIdentifier, []ResourceIdentifier, or nil
	Meta  *Meta  `json:"meta,omitempty"`
}

Relationship represents a JSON:API relationship.

type Relationships

type Relationships map[string]*Relationship

Relationships maps relationship names to their data.

type RepositoryAttributes

type RepositoryAttributes struct {
	RemoteURI      string     `json:"remote_uri"`
	CreatedAt      *time.Time `json:"created_at,omitempty"`
	UpdatedAt      *time.Time `json:"updated_at,omitempty"`
	LastScannedAt  *time.Time `json:"last_scanned_at,omitempty"`
	ClonedPath     *string    `json:"cloned_path,omitempty"`
	TrackingBranch *string    `json:"tracking_branch,omitempty"`
	NumCommits     int        `json:"num_commits"`
	NumBranches    int        `json:"num_branches"`
	NumTags        int        `json:"num_tags"`
}

RepositoryAttributes represents repository attributes in JSON:API format.

type RepositoryDetailsResponse

type RepositoryDetailsResponse struct {
	Data          *Resource          `json:"data"`
	Branches      []BranchData       `json:"branches"`
	RecentCommits []RecentCommitData `json:"recent_commits"`
}

RepositoryDetailsResponse represents repository details with branches and commits.

type Resource

type Resource struct {
	Type          string        `json:"type"`
	ID            string        `json:"id"`
	Attributes    any           `json:"attributes"`
	Relationships Relationships `json:"relationships,omitempty"`
	Links         *Links        `json:"links,omitempty"`
	Meta          *Meta         `json:"meta,omitempty"`
}

Resource represents a JSON:API resource object. See: https://jsonapi.org/format/#document-resource-objects

func NewResource

func NewResource(resourceType, id string, attrs any) *Resource

NewResource creates a new resource with the given type, id and attributes.

type ResourceIdentifier

type ResourceIdentifier struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

ResourceIdentifier identifies a resource without full attributes.

type Serializer

type Serializer struct{}

Serializer converts domain objects to JSON:API resources.

func NewSerializer

func NewSerializer() *Serializer

NewSerializer creates a new Serializer.

func (*Serializer) CommitResource

func (s *Serializer) CommitResource(commit repository.Commit) *Resource

CommitResource converts a commit to a JSON:API resource.

func (*Serializer) CommitResources

func (s *Serializer) CommitResources(commits []repository.Commit) []*Resource

CommitResources converts multiple commits to JSON:API resources.

func (*Serializer) EnrichmentResource

func (s *Serializer) EnrichmentResource(e enrichment.Enrichment) *Resource

EnrichmentResource converts an enrichment to a JSON:API resource.

func (*Serializer) EnrichmentResources

func (s *Serializer) EnrichmentResources(enrichments []enrichment.Enrichment) []*Resource

EnrichmentResources converts multiple enrichments to JSON:API resources.

func (*Serializer) FileResource

func (s *Serializer) FileResource(file repository.File) *Resource

FileResource converts a file to a JSON:API resource.

func (*Serializer) FileResources

func (s *Serializer) FileResources(files []repository.File) []*Resource

FileResources converts multiple files to JSON:API resources.

func (*Serializer) RepositoryResource

func (s *Serializer) RepositoryResource(source repository.Source) *Resource

RepositoryResource converts a repository source to a JSON:API resource.

func (*Serializer) RepositoryResources

func (s *Serializer) RepositoryResources(sources []repository.Source) []*Resource

RepositoryResources converts multiple sources to JSON:API resources.

func (*Serializer) StatusSummaryResource

func (s *Serializer) StatusSummaryResource(repoID int64, summary tracking.RepositoryStatusSummary) *Resource

StatusSummaryResource converts a status summary to a JSON:API resource.

func (*Serializer) TagResource

func (s *Serializer) TagResource(tag repository.Tag) *Resource

TagResource converts a tag to a JSON:API resource.

func (*Serializer) TagResources

func (s *Serializer) TagResources(tags []repository.Tag) []*Resource

TagResources converts multiple tags to JSON:API resources.

func (*Serializer) TaskResource

func (s *Serializer) TaskResource(t task.Task) *Resource

TaskResource converts a task to a JSON:API resource.

func (*Serializer) TaskResources

func (s *Serializer) TaskResources(tasks []task.Task) []*Resource

TaskResources converts multiple tasks to JSON:API resources.

func (*Serializer) TaskStatusResource

func (s *Serializer) TaskStatusResource(status task.Status) *Resource

TaskStatusResource converts a task status to a JSON:API resource.

func (*Serializer) TaskStatusResources

func (s *Serializer) TaskStatusResources(statuses []task.Status) []*Resource

TaskStatusResources converts multiple statuses to JSON:API resources.

func (*Serializer) TrackingConfigResource

func (s *Serializer) TrackingConfigResource(repoID int64, tc repository.TrackingConfig) *Resource

TrackingConfigResource converts a tracking config to a JSON:API resource.

type StatusSummaryAttributes

type StatusSummaryAttributes struct {
	Status    string    `json:"status"`
	Message   string    `json:"message"`
	UpdatedAt time.Time `json:"updated_at"`
}

StatusSummaryAttributes represents status summary attributes in JSON:API format.

type TagAttributes

type TagAttributes struct {
	Name            string `json:"name"`
	TargetCommitSHA string `json:"target_commit_sha"`
	IsVersionTag    bool   `json:"is_version_tag"`
}

TagAttributes represents tag attributes in JSON:API format.

type TaskAttributes

type TaskAttributes struct {
	Type      string     `json:"type"`
	Priority  int        `json:"priority"`
	Payload   any        `json:"payload"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

TaskAttributes represents task attributes in JSON:API format.

type TaskStatusAttributes

type TaskStatusAttributes struct {
	Step      string     `json:"step"`
	State     string     `json:"state"`
	Progress  float64    `json:"progress"`
	Total     int        `json:"total"`
	Current   int        `json:"current"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	Error     string     `json:"error"`
	Message   string     `json:"message"`
}

TaskStatusAttributes represents task status attributes in JSON:API format.

type TrackingConfigAttributes

type TrackingConfigAttributes struct {
	Mode  string  `json:"mode"`
	Value *string `json:"value,omitempty"`
}

TrackingConfigAttributes represents tracking config attributes in JSON:API format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL