generated from martinthomson/internet-draft-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Propose targettype keyword for associations #8
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
Open
Fannon
wants to merge
1
commit into
json-structure:main
Choose a base branch
from
Fannon:add-targettype-keyword
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1051,6 +1051,47 @@ schema definition, including in type unions. | |||||
| `$ref` is NOT permitted in other attributes and MUST NOT be used inside the | ||||||
| `type` of the root object. | ||||||
|
|
||||||
| ### `targettype` Keyword {#targettype-keyword} | ||||||
|
|
||||||
| The `targettype` keyword can be used to indicate an association / reference / | ||||||
| pointer to an object, using its primary IDs. With this information, consumers | ||||||
| know how data can be joined together and how to construct references correctly. | ||||||
|
|
||||||
| Note: Only in the case of a single primary ID it's clear how the reference | ||||||
| property maps to the target object ID. In case of composite IDs, the | ||||||
| references become composite references, where the mapping from multiple | ||||||
| reference properties to multiple target IDs need to be explicitly maintained. | ||||||
| This goes beyond the scope of the core spec. | ||||||
|
|
||||||
| Example: | ||||||
|
|
||||||
| ~~~ json | ||||||
| { | ||||||
| "$schema": "https://json-structure.org/meta/core/v0/#", | ||||||
| "$id": "https://schemas.vasters.com/TypeName", | ||||||
| "definitions": { | ||||||
| "Namespace": { | ||||||
| "Person": { | ||||||
| "name": "Person", | ||||||
| "type": "object", | ||||||
| "id": ["ID"], | ||||||
| "properties": { | ||||||
| "ID": { "type": "string" }, | ||||||
| "archenemy": { | ||||||
| "type": "string" | ||||||
| "targettype": ""$ref": "#/Namespace/Person"" | ||||||
| }, | ||||||
| } | ||||||
| }, | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| ~~~ | ||||||
|
|
||||||
| The `targettype` MUST only be used on object properties. | ||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @clemensv : Could it also appear in set and tuple?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You clarified it in another comment.
Suggested change
|
||||||
| The value MUST be a valid JSON Pointer to the association target object, | ||||||
| which MUST provide the `id` keyword to indicate its primary IDs. | ||||||
|
|
||||||
| ### Cross-references {#cross-references} | ||||||
|
|
||||||
| In JSON Structure documents, the `$schema` keyword references the meta-schema of | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other possible keyword names:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the direction of this, but I would make this broader:
For objects and tuples, I would add a new keyword "relations" that is similar to "properties" but specifically defines relationship properties. "relations" and "properties" share a namespace, so they can't define conflicting names.
The "relations" declarations are not modeled as types, because they must be able to cross-reference properties within the same tuple/object. They are similar to properties in that they are represented just like properties in the instances.
A
relationis a named object (via therelationsmap) that has two properties:targettypedeclares the target type that the relation refers tocardinalitydeclares whether the relationship point to one or more targetsthe targettype's
identitydeclaration functions like thetuplekeyword for establishing the type of references, meaning that if the target'sidentityclause references two properties, the reference value in the relation source is a tuple-encoded list of values matching that identity.An instance of a single relation is an object with the following properties:
"ref" : a JSON pointer to the target object
"identity": a tuple that reflects the target object identity values
A relationship MAY be established either through a direct link (ref) or through an
identitymatch against all known instances of the target type. If both properties are defined, theidentitymatch is performed against all instances of the target type that exists within the scope of therefjson pointer, i.e. are children of the identified node.the value of relations with
multiplecardinality is an array of such objects. the value of relations withsinglecardinality is a single such object.Instance:
I explicitly made the
relationinstance an object, because that gives us the opportunity to declare aqualifiertype in therelationwhich defines/references a type to qualify the relationship further, equivalent to link properties in a graph.Example:
qualifier type:
extend the relation:
Instance with qualifiers:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like where this is going, thanks for creating this example!
Moving it to its own
relationproperty as an array of object seems like a really good idea.Where I'm unsure is if we can assume that the instances are structured like you propose. I see how it's nice to make each reference an object and for convenience also adding a "ref", but in many real data cases I've seen the references are just a string property or an array of strings. The concept also needs to work with this. So the "reference" in the schema has to point to the property that carries the ID of the reference, too?
Let me get back on this to you when I have more time to think it through.