Skip to content

Add resource identifier metadata marshaling - #81

Merged
skarimo merged 2 commits into
DataDog:mainfrom
ryanscottaudio:resource-identifier-meta
Sep 16, 2026
Merged

skarimo merged 2 commits into
DataDog:mainfrom
ryanscottaudio:resource-identifier-meta

Conversation

@ryanscottaudio

@ryanscottaudio ryanscottaudio commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Related Issue

#80

Description

This change adds the optional MarshalResourceIdentifierMeta interface. Related resources can implement it to add metadata to each resource identifier object.

For example:

type Layer struct {
	ID    string `jsonapi:"primary,layers"`
	Nodes []Node `jsonapi:"relationship" json:"nodes"`
}

type Node struct {
	ID    string `jsonapi:"primary,nodes"`
	Index int
}

func (n Node) MarshalResourceIdentifierMeta() any {
	return map[string]any{"index": n.Index}
}

jsonapi.Marshal(Layer{
	ID: "layer-a",
	Nodes: []Node{
		{ID: "node-a", Index: 0},
		{ID: "node-b", Index: 1},
	},
})

The relationship data now contains distinct metadata on each resource identifier:

{
  "data": {
    "type": "layers",
    "id": "layer-a",
    "relationships": {
      "nodes": {
        "data": [
          {"type": "nodes", "id": "node-a", "meta": {"index": 0}},
          {"type": "nodes", "id": "node-b", "meta": {"index": 1}}
        ]
      }
    }
  }
}

Previously, jsonapi:"meta" could only add metadata to the relationship object itself. Adding per-identifier metadata required modifying the encoded JSON after marshaling.

The existing relationship-object metadata behavior is unchanged. Identifier metadata uses the existing metadata validation, omits nil values, and preserves an empty metadata object.

Additional context

Tests cover to-one and to-many relationships, distinct metadata, nil and typed nil values, empty objects, invalid values, and both metadata locations together.

Local checks passed:

  • go test ./...
  • go test -race ./...
  • go vet ./...

@ryanscottaudio
ryanscottaudio force-pushed the resource-identifier-meta branch from a835709 to 36658a1 Compare September 8, 2026 19:51
@ryanscottaudio
ryanscottaudio marked this pull request as ready for review September 8, 2026 19:52
Comment thread jsonapi.go
@ryanscottaudio

Copy link
Copy Markdown
Contributor Author

/code blockers

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-15 17:24:35 UTC ℹ️ Start processing command /code blockers


2026-09-15 17:24:36 UTC ℹ️ Devflow:

Checking merge blockers for #81...


2026-09-15 17:24:42 UTC ℹ️ Devflow: /code blockers

Detected 1 merge blocker(s) to address:

🔴 Blocking

  • This pull request contains unsigned commits.
    Commit bb78033 is not signed.
    Hint: Sign your commits, then force-push. See our FAQ.

@ryanscottaudio

Copy link
Copy Markdown
Contributor Author

/remove

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-15 17:44:06 UTC ℹ️ Start processing command /remove


2026-09-15 17:44:13 UTC ℹ️ Devflow: /remove

@ryanscottaudio

Copy link
Copy Markdown
Contributor Author

/code blockers

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-15 17:47:15 UTC ℹ️ Start processing command /code blockers


2026-09-15 17:47:15 UTC ℹ️ Devflow:

Checking merge blockers for #81...


2026-09-15 17:47:22 UTC ℹ️ Devflow: /code blockers

No merge blockers detected.

@ryanscottaudio

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-15 17:50:12 UTC ℹ️ Start processing command /merge


2026-09-15 17:50:15 UTC ❌ MergeQueue

PR already in the queue with status in_progress

@ryanscottaudio

Copy link
Copy Markdown
Contributor Author

/remove

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-15 17:50:57 UTC ℹ️ Start processing command /remove


2026-09-15 17:51:04 UTC ℹ️ Devflow: /remove

@ryanscottaudio

Copy link
Copy Markdown
Contributor Author

/merge -m squash

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Sep 15, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-09-15 17:51:14 UTC ℹ️ Start processing command /merge -m squash


2026-09-15 17:51:21 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 0s (p90).


2026-09-15 19:51:42 UTCMergeQueue: The build pipeline has timeout

The merge request has been interrupted because the build 0 took longer than expected. The current limit for the base branch 'main' is 120 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants