Closed glucaci closed 18 hours ago
1-555-123-4567 is a valid URI reference. It's unusual for sure, but it's valid.
Here's some sample code showing it in action:
using CloudNative.CloudEvents;
using CloudNative.CloudEvents.SystemTextJson;
using System.Text;
var evt = new CloudEvent
{
Id = "my-id",
Source = new Uri("1-555-123-4567", UriKind.RelativeOrAbsolute),
Type = "my-type"
};
evt.Validate();
CloudEventFormatter formatter = new JsonEventFormatter();
var bytes = formatter.EncodeStructuredModeMessage(evt, out _);
var json = Encoding.UTF8.GetString(bytes.Span);
Console.WriteLine(json);
Output:
{"specversion":"1.0","id":"my-id","source":"1-555-123-4567","type":"my-type"}
Fundamentally, the Source
property is a Uri
because the type of the source
attribute (see the spec examples link you had before) is URI-reference
.
Thanks for the clarification, but then why Microsoft decided to use a string
type on the Source
property is a good question.
I can't answer that, I'm afraid. I'm going to close this issue now as I believe I've answered it as thoroughly as I can.
Hi,
I wanted to write a mapping between the Azure.Messaging.CloudEvent which is JSON spec conform and the
CloudNative.CloudEvents.CloudEvent
and realized the difference on theSource
Property type.There is any reason why in
CloudNative.CloudEvents.CloudEvent
theSource
property isUri
because inAzure.Messaging.CloudEvent
it's astring
.Also taking a look of the spec examples and taking the value
1-555-123-4567
, can be seen that this is not a valid value for anUri
type.Thanks for clarification!