-
Notifications
You must be signed in to change notification settings - Fork 583
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
add json serialization #124
Conversation
9a6e2c7
to
3d5a1cd
Compare
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.
A few minor comments.
"cloud-events-version": "cloud-events-version value", | ||
"event-id": "event-id value", | ||
"namespace": "namespace value", | ||
"source": { |
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.
@duglin isn't source
a URI?
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.
Not yet :-)
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.
Fair enough. Pending #123 🙂
serialization.md
Outdated
} | ||
``` | ||
|
||
Note: |
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.
nitpicking - sais Note
, but these are notes.
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.
fixed
serialization.md
Outdated
``` | ||
|
||
Note: | ||
- the use of whitespace is not significant |
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.
Capitalize?
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.
fixed
349dab1
to
c4fd2d5
Compare
serialization.md
Outdated
@@ -0,0 +1,43 @@ | |||
# CloudEvents Serialization Profile - Version 0.1 | |||
|
|||
This document specified how a CloudEvent is to be serialized into certain |
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.
Should this be applied here? s/specified/specifies/
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.
fixed the "specified" typo. What did you mean by "should this applied here?" ?
} | ||
``` | ||
|
||
Notes: |
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.
Should there be a comment about extra fields in the serialized data? Such as:
- It is undefined whether extra fields are passed along or removed depending on the usage role and implementation. Those fields are best placed in the extensions map.
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 expanded on the thought a little - see what you think.
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.
Thanks for the update. LGTM.
} | ||
``` | ||
|
||
Notes: |
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.
Thanks for the update. LGTM.
spec.md
Outdated
@@ -26,6 +26,11 @@ Enter CloudEvents, a specification for describing event data in a common way. | |||
CloudEvents seeks to ease event declaration and delivery across services, | |||
platforms and beyond. | |||
|
|||
The [Serialization Profile](serialization.md) specified how to |
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.
This might be better as "specifies". (Or am I being too tense?)
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.
No, you're right - just a disconnect between the brain and fingers.
|
||
``` | ||
{ | ||
"cloud-events-version": "cloud-events-version value", |
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'm curious whether it would be more useful to use valid fake values rather than prose in quotes.
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 struggled with this because if we put fake values in there then we need something to say "property X from the spec goes into json property 'x'". While in many cases it should be really really obvious, I felt that a spec should be more explicit about it. If all we cared about was JSON I actually would have proposed that we have the serialization of each property next to its definition in the spec itself. But I didn't want to assume everyone would be ok with JSON getting special treatment.
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.
@inlined I added an example to try to address your concern. See if that helps.
"extensions": { | ||
... extensions values ... | ||
}, | ||
"data": ... data value ... |
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.
As an FYI: though Google&Firebase started out with a model like this where all context is at the top level with one magic field called "data", we generally considered this to be a mistake. Many languages have better ways to expose context (e.g. Golang's Context.context
, or JavaScript's variadic parameter system) so we are migrating to a world where data & context are exposed separately/natively our runtimes. Alpha testers have given very positive feedback for this because it allows any existing function(SomeNativeType) to be a CloudFunction<SomeNativeType>.
To match this, the REST JSON is being migrated to a two-field JSON object with {"context", "data"}
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 could live with that. What do other people think?
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.
@inlined would extensions
be under context
or another sibling at the root level?
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.
@inlined where would "could-events-version" go? I can see it being useful as a top-level thing since we may choose to rename data
or context
in a future version, but I can also see a need for that info to be passed downstream so people know how to interpret the context
attributes based on our spec's version number.
I do want to explore this option, it feels cleaner - would make for a great follow-on PR
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.
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.
would that be something that the definition of the content-type (e.g. json spec) would need to define?
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.
afaik json spec does not cover this explicitly. Most people seem to base64 encode data.
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.
yea, I did a quick search too and didn't find a lot. I guess we could offer some recommendations...
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.
Honestly I don't have the practical experience with content-type
and cloud-events-version
that I do with the other fields. Here's my first SWAG:
- In my opinion,
content-type
is/should be meta to the whole spec (why are we dictating the content type within a payload that's already explicitly JSON encoded?). This should be dictated in the transport layer, not the encoding layer. cloud-events-version
looks cleanest at the top level in JSON though if it's going to show up in the programming model it might be easier to put it incontext
.- I have the strong opinion (weakly held) that
extensions
should be incontext
. The developer is likely to depend on these extensions and they should be easily accessible.
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.
@inlined My understanding is that this PR is about how to package an arbitrary cloudevent into json. I was just wondering what happens if the content-type (the context attribute) is text/xml or image/png. The result is supposed to be a valid json object. So data would need to be encoded somehow. I don't see how this can be delegated to another layer. For events that use json for their data section, there is of course no need for encoding.
Signed-off-by: Doug Davis <dug@us.ibm.com>
Signed-off-by: Doug Davis <dug@us.ibm.com>
Added an example and one line to make it clear that optional fields are still optional, but if present then they MUST adhere to the rules defined. I think it was implied before but now its explicitly stated. |
This will have to be modified to be consistent with changed accepted today |
Approved on 3/29 call |
Closes #17
I would actually prefer if we just move this into the main spec itself since its so small, but for now I started out with it being in a separate doc with the assumption that we can decide on whether we want to merge it later.
Signed-off-by: Doug Davis dug@us.ibm.com