Skip to content

Commit 9ccd339

Browse files
committed
bugfix_value_type_of_dataschema
Signed-off-by: Tim Brunko <timmyb32r@gmail.com>
1 parent 39fe13d commit 9ccd339

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

binding/format/protobuf/v2/protobuf.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ func ToProto(e *event.Event) (*pb.CloudEvent, error) {
8888
container.Attributes[datacontenttype], _ = attributeFor(e.DataContentType())
8989
}
9090
if e.DataSchema() != "" {
91-
container.Attributes[dataschema], _ = attributeFor(e.DataSchema())
91+
dataSchemaStr := e.DataSchema()
92+
uri, err := url.Parse(dataSchemaStr)
93+
if err != nil {
94+
return nil, fmt.Errorf("failed to url.Parse %s: %s", dataSchemaStr, err)
95+
}
96+
container.Attributes[dataschema], _ = attributeFor(uri)
9297
}
9398
if e.Subject() != "" {
9499
container.Attributes[subject], _ = attributeFor(e.Subject())
@@ -251,8 +256,8 @@ func FromProto(container *pb.CloudEvent) (*event.Event, error) {
251256
vs, _ := v.(string)
252257
e.SetDataContentType(vs)
253258
case dataschema:
254-
vs, _ := v.(string)
255-
e.SetDataSchema(vs)
259+
vs, _ := v.(types.URI)
260+
e.SetDataSchema(vs.String())
256261
case subject:
257262
vs, _ := v.(string)
258263
e.SetSubject(vs)

binding/format/protobuf/v2/protobuf_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func TestFromProto(t *testing.T) {
109109
Type: "some.type",
110110
Attributes: map[string]*pb.CloudEventAttributeValue{
111111
"datacontenttype": {Attr: &pb.CloudEventAttributeValue_CeString{CeString: "application/json"}},
112+
"dataschema": {Attr: &pb.CloudEventAttributeValue_CeUri{CeUri: "link"}},
112113
"extra1": {Attr: &pb.CloudEventAttributeValue_CeString{CeString: "extra1 value"}},
113114
"extra2": {Attr: &pb.CloudEventAttributeValue_CeInteger{CeInteger: 2}},
114115
"extra3": {Attr: &pb.CloudEventAttributeValue_CeBoolean{CeBoolean: true}},
@@ -124,6 +125,7 @@ func TestFromProto(t *testing.T) {
124125
out.SetSource("/source")
125126
out.SetType("some.type")
126127
_ = out.SetData("application/json", map[string]interface{}{"unit": "test"})
128+
out.SetDataSchema("link")
127129
out.SetExtension("extra1", "extra1 value")
128130
out.SetExtension("extra2", 2)
129131
out.SetExtension("extra3", true)
@@ -140,6 +142,7 @@ func TestFromProto(t *testing.T) {
140142
Type: "some.type",
141143
Attributes: map[string]*pb.CloudEventAttributeValue{
142144
"datacontenttype": {Attr: &pb.CloudEventAttributeValue_CeString{CeString: "text/plain"}},
145+
"dataschema": {Attr: &pb.CloudEventAttributeValue_CeUri{CeUri: "link"}},
143146
"extra1": {Attr: &pb.CloudEventAttributeValue_CeString{CeString: "extra1 value"}},
144147
"extra2": {Attr: &pb.CloudEventAttributeValue_CeInteger{CeInteger: 2}},
145148
"extra3": {Attr: &pb.CloudEventAttributeValue_CeBoolean{CeBoolean: true}},
@@ -155,6 +158,7 @@ func TestFromProto(t *testing.T) {
155158
out.SetSource("/source")
156159
out.SetType("some.type")
157160
_ = out.SetData("text/plain", `this is some text with a "quote"`)
161+
out.SetDataSchema("link")
158162
out.SetExtension("extra1", "extra1 value")
159163
out.SetExtension("extra2", 2)
160164
out.SetExtension("extra3", true)
@@ -171,6 +175,7 @@ func TestFromProto(t *testing.T) {
171175
Type: "some.type",
172176
Attributes: map[string]*pb.CloudEventAttributeValue{
173177
"datacontenttype": {Attr: &pb.CloudEventAttributeValue_CeString{CeString: "application/json"}},
178+
"dataschema": {Attr: &pb.CloudEventAttributeValue_CeUri{CeUri: "link"}},
174179
"extra1": {Attr: &pb.CloudEventAttributeValue_CeString{CeString: "extra1 value"}},
175180
"extra2": {Attr: &pb.CloudEventAttributeValue_CeInteger{CeInteger: 2}},
176181
"extra3": {Attr: &pb.CloudEventAttributeValue_CeBoolean{CeBoolean: true}},
@@ -186,6 +191,7 @@ func TestFromProto(t *testing.T) {
186191
out.SetSource("/source")
187192
out.SetType("some.type")
188193
_ = out.SetData("application/json", `{"unit":"test"}`)
194+
out.SetDataSchema("link")
189195
out.SetExtension("extra1", "extra1 value")
190196
out.SetExtension("extra2", 2)
191197
out.SetExtension("extra3", true)

0 commit comments

Comments
 (0)