From 150f30607431752fd6249b0d42cec7ed3331c002 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Fri, 12 Dec 2025 14:01:47 +0100 Subject: [PATCH] Consider nil `*Link`s as per se valid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nothing in the JSON:API spec requires links (usually e.g. it’s either links or data), and nothing requires that if one relation has a related resource link, all must. This allows `LinkRelation` to return nil for related resources which may not have exposed linkage routes in an API. --- jsonapi.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jsonapi.go b/jsonapi.go index 0f8aa2f..04b4a44 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -109,6 +109,10 @@ func checkLinkValue(linkValue any) (bool, *TypeError) { } func (l *Link) check() error { + if l == nil { + return nil + } + selfIsEmpty, err := checkLinkValue(l.Self) if err != nil { return err