-
-
Notifications
You must be signed in to change notification settings - Fork 308
Hyper-schema: Alternative forms for listing link relationships #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm definitely in favor of this. I always have to translate the links into something like this inside code anyway because searching a list for the right rel value is really awkward. |
I only see one minor downside to this, and it's consistency in a different sense - when |
My minor concern also applies to |
No, rel is always the key. It's never in the LDO as written out. The only cases to handle are whether there is one LDO attached to rel (the value is an object) or several (the value is an array of LDO objects). This can be normalized as the hyper-schema is read in. |
Having given this some thought and looked at other media types more, I think I am reluctantly against this.
It's easy enough to internally parse things into a dict but, at least based on RFC 5988 link-to-rel is a many-to-many relationship and the current LDO format is better for that. |
Sorry. LOD? |
@Relequestual LDO == Link Description Object, a.k.a. the elements of the |
Right. I understand what an LDO is now. yay. I'm struggling to work out what problem this issue is raising or trying to solve. Could the problem be rephrased with a clear problem statement, with an explanation of the suggested fix please? |
@Relequestual The At first glance, an array looks difficult to work with. If the link relation name is the important thing about finding which link to use, why not just make it an object keyed by link relation name? I think everyone starts out looking at the We were thinking of link types that were designed to appear only once, or if they did appear multiple times, each link was anchored to a separate point in the JSON representation (for example, representing a collection as an array of ids, and associating an "item" link with each id- there are many "item" links, but they just need to be specified once in the schema). So I feel strongly that while using link relation names as a key seems nice at first, it is a trap and we should stick with the existing list approach. Otherwise, we need to do annoying things like have each link relation name take either an LDO or a list of LDOs (annoying to process) or make each link name map to a list of LDOs, even if that list often only has one LDO in it (annoying on general principle). Does that help? |
OK. Thanks for the explanation. Unless we can get some reasoning from the other projects as to why they chose to do it that way, and why they consider it's preferable to our current approach, I'm against making this change. Following the crowd is sometimes the way to go, but only if there is valid reason beyond simply following for followings sake. |
I've since come around to the array approach. It more closely matches formats such as HTTP's link header. The main argument I can see in favor of the object approach is that most of the situations involving multiple links with the same relation type are handled by URI templating for us. However, if an application wanted to generate an LDO list at runtime that is already fully resolved, then having it be in list format would make it easy to produce such a thing. I'd like to make a decision on this one way or another, as it's a pretty fundamental thing for parsers to work with. @awwright or anyone else still want to advocate for this change? |
On the other hand, HTTP headers could not be represented as objects so I'm not sure how far the comparison can go. The array model always looked strange to me, probably because other hypermedia formats use an object as mentioned above (interestingly, in JSON Home "links" is an object). I don't know the reason for this in other formats, but do we know the reason behind our array model? I guess one reason is that |
|
I'm not dead set against changing this, but as @Relequestual notes it shouldn't just be because it seems a bit more convenient at casual glance. Sadly, I don't think anyone still here was involved in that decision. @philsturgeon @geemus @dret any thoughts on this one? I really think that if we do make it an object, then the value of each property needs to be an array to avoid the annoying "is this an object or array" check while working with the structure in memory. Is that really better? Maybe it is, I'm persuadable. But since I feel like draft-07 will be the first really-close-to-feature-complete version of Hyper-Schema, I'd like to get this nailed down one way or the other. Hopefully we will start seeing implementations now, and I don't want to thrash on the fundamental data structure. |
this is too far into specific details for me to contribute to. but we had similar discussions when resolving dret/I-D#73. the fun fact underneath is that even though the HTTP |
Thanks, @dret! That all makes sense. It also ties into #350 (how to handle multiple Having However, if you can I think the biggest minus is that LDOs were clearly designed to be usable outside of JSON Hyper-Schema, which is why there is a separate |
@handrews The one-link-per-rel case does seem more common, and referencing by rel-keys is easier than selecting across rel values for all objects in and array. It is a big change for the sake of convenience, which may or may not be good. It does seem like a good idea to say that if it changed from an array of objects to an object, that it should be an object of arrays (instead of having to do the tedious and easy to forget object or array logic). We definitely locally enforce "just always array so that things are easier" in our usage where there are other object-or-array cases. TLDR: this change sounds nice. I fear the result is a bit sugary/magical though and is perhaps not consistent with other parts of the schema which tend to be rather explicit. I can definitely imagine it being easier to use/reason about though, so I'm torn. |
Yeah, me too. If we don't reach a fairly clear consensus on changing this I'm probably inclined to leave it as-is. If we want LDOs to each be self-contained, then they should stay individual objects in an array with a The current way definitely feels nicer for working with a single link, and reasoning about the individual LDO as an RFC 5988bis-style link serialization format. |
I'd really like to decide this for draft-07. Does anyone want to advocate for making the change? @awwright? @Anthropic? One thing that might help is to look at how a minimal single link, or multiple links, would look. For a single, minimal link: {"rel": "related", "href": "/foos"} vs {"related": [{"href": "/foos"}]} For two links with the same relation: [
{"rel": "related", "href": "/foos"},
{"rel": "related", "href": "/bars"}
] vs {
"related": [
{"href": "/foos"},
{"href": "/bars"}
]
} Adding a third link with a different relation: [
{"rel": "related", "href": "/foos"},
{"rel": "related", "href": "/bars"},
{"rel": "author", "href": "/people/{authorId}"}
] vs {
"related": [
{"href": "/foos"},
{"href": "/bars"}
],
"author": [
{"href": "/people/{authorId}"}
]
} |
As a number of people are indifferent about this change, it feels like wasted effort to continue discussing it till someone can come up with clear reason why it's "better". It may look slighly cleaner, but I'm more interested in the effect it would have on implementations, which is some. For now I'd be inclined to close the issue. If anyone can strongly argue why it would be an improvement, please do so, and we can re-open or create a new issue. |
@Relequestual that is a really good point about implementations, and has made me think things through again a little differently. I'm going to line up the pros and cons that I see and make a (possibly overly complicated) strawman proposal:
|
@handrews I like your strawman proposal and I'd thus be in favor of a change. |
I've encountered some other arguments for stand-alone links elsewhere, and we are already changing a lot of things in hyper-schema right now. I am also increasingly leaning against changing this. I would like to defer it for consideration once we have people looking at hyper-schema more seriously, which hopefully this draft will accomplish. |
Coming back to this, I'm still inclined to stay with the array. While I can't find the right issue comment right now, the Web of Things group ended up going with an array after initially considering an object. And they have a lot more people with a lot more hypermedia experience contributing to their spec than we do :-) The biggest problem that I see with the array is that it's impossible to reliably address links with a JSON Pointer, should we want to do so. Position-based indexing is inherently fragile when the position has no semantic meaning. In such situations, people often re-order the LDOs for whatever aesthetic reasons (e.g. documentation presentation). On the other hand, having a defined (if not semantically meaningful) order is very useful for documentation presentation. An alternative to JSON Pointer addressing could be to extend the ability to declare a plain-name fragment to links. I'm not sure how this would need to work with the core spec and media type definition. I'd be reluctant to allow Setting aside the mechanism (we can hammer that out if we actually think this is a good idea), being able to give an LDO a plain-name fragment identifier would allow it to be addressed independent of location within the document. Potential use cases for this include:
Those use cases aren't strong enough to justify this so far, but I'm putting it out there to hopefully spur some thought. |
It's been more than six months since I said I was leaning against changing this, and nearly a month since my last comment. Which has much more to do with issue #319 ( No one has emerged to champion a clear alternative, so I'm closing this out. We will stick with the array. |
For a variety of cases, it's often simpler to use:
or:
HAL and other JSON-based hypermedia formats follow a similar convention.
The text was updated successfully, but these errors were encountered: