Conversation
dcb8995 to
adcb72d
Compare
|
|
||
| The content inside JSON Serialisation MUST always be a Refracted element, an | ||
| array of Refracted element or a primitive type such as string, number, boolean | ||
| or none. The only exceptions to this rule is for any element types described |
There was a problem hiding this comment.
I don't understand why there is a need for the last sentence here.
There was a problem hiding this comment.
There are exceptions to the rule I outlined as member stores a JSON object directly as content instead. Any element in the core Refract specification can provide exceptions to these rules.
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "id"
},
"value": {
"element": "string",
"content": "Hello"
}
}
}There was a problem hiding this comment.
One thing that could be done here is to make the content of the "Member Element" to be it's own definition (maybe a Key Value Object or something). Then you can be more specific to say it MUST be:
- Refracted element
- Array of refracted elements
- Values (string, number, boolean)
- Key Value Object
- None
Just a thought. Is there any other value from the spec?
There was a problem hiding this comment.
Element Pointer and Link Element have direct objects.
There was a problem hiding this comment.
I do not think Link Element actually would be exclusions to this rule.
Link Element does not use content and does not have direct content at all. It only supports href and relation as ATTRIBUTES not inside content.
** Element Pointer** on the other hand does use an enum where the value may be an object, but I wonder if we can simplify the element pointer value to be a string element with an attribute instead.
Currently the following is defined in the spec for the value for Element Pointer:
Members
- (string) - A URL to an ID of an element in the current document
- (object) - The URL and path of the referenced element
href(string, required) - URL or ID of elementpath(enum) - Path of referenced element to transclude instead of element itself
- meta - The meta data of the referenced element
- attributes - The attributes of the referenced element
- content - The content of the referenced element
Perhaps this could be simplified to an element:
+ attributes
+ path (enum, optional)
+ meta - The meta data of the referenced element
+ attributes - The attributes of the referenced element
+ content - The content of the referenced element
+ content (string)That way, the only "special-cased" is member, which we can say the value is a "key-value pair" as @smizell suggests.
There was a problem hiding this comment.
@kylef I like that. Are you using that anywhere that would be broken?
Also, you may want to define another value for path to say the pointer points to either:
- The entire element
- The meta of the element
- The attributes of the element
- The content of the element
There was a problem hiding this comment.
I've moved Element Pointer to a separate PR: #38
I'm not sure on what It may break, but since we control most of the tooling that produces and consumes Refract/API Elements it is a better time than any to simplify and improve the specification for any wider consumption.
| For example, it is NOT possible to serialise an arbitrary object inside the | ||
| content value for elements not defined within the base Refract specification. | ||
| Otherwise it can be ambiguous for consumers whether the JSON object is another | ||
| element or JSON data. |
There was a problem hiding this comment.
Just a note here, we put a couple of rules in the spec to make this possible I think (unless I'm missing something).
- The
elementproperty is required for all Refract elements. - The
elementproperty is reserved in a Refract document
I don't think we've worked through this a lot, but it seems it may allow for arbitrary objects or arrays to be within the content, meta, or attributes while ensuring a serializer/deserializer can make decisions.
There was a problem hiding this comment.
Yeah, reserving element keyword will help fix this issue. (And we did). But IMO we want the serialisation rules to be more stricter and thus if content is an object, we want it to be fully serialized as object element.
There was a problem hiding this comment.
Unfortunately, I can't find the line about the second point. I'm thinking maybe we didn't put it in the spec and chose to use it as a rule in the libraries. Maybe it should make it in the spec to make some of this easier?
There was a problem hiding this comment.
To clarify, not saying it should go into the main spec, but agree there should be some serialization/deserialization spec and maybe this rule should go there. If it does, it may make for a simpler set of rules.
There was a problem hiding this comment.
Sorry @pksunkara, I had to refresh to see your comment. I see what you're saying—makes sense to me.
adcb72d to
0a3dc34
Compare
This pull request aims to resolve some ambiguities in the current informal serialisation along with pave the way to having a full clear specification for full Refract serialisation which currently is not defined.
Many implementations do not support both refracted and un-refracted JSON data in many places leading to Refract tooling that is coupled to JSON serialisation. This PR attempts to resolve these problems by:
This would supersede #17.