@@ -25,7 +25,9 @@ internal CloudEventAttributes(CloudEventsSpecVersion specVersion, IEnumerable<IC
2525 {
2626 this . extensions = extensions ;
2727 this . specVersion = specVersion ;
28- dict [ SpecVersionAttributeName ( specVersion ) ] = specVersion == CloudEventsSpecVersion . V0_1 ? "0.1" : "0.2" ;
28+ dict [ SpecVersionAttributeName ( specVersion ) ] =
29+ specVersion == CloudEventsSpecVersion . V0_1 ? "0.1" :
30+ specVersion == CloudEventsSpecVersion . V0_2 ? "0.2" : "0.3" ;
2931 }
3032
3133 int ICollection < KeyValuePair < string , object > > . Count => dict . Count ;
@@ -42,9 +44,12 @@ public CloudEventsSpecVersion SpecVersion
4244 {
4345 object val ;
4446 if ( dict . TryGetValue ( SpecVersionAttributeName ( CloudEventsSpecVersion . V0_1 ) , out val ) ||
45- dict . TryGetValue ( SpecVersionAttributeName ( CloudEventsSpecVersion . V0_2 ) , out val ) )
47+ dict . TryGetValue ( SpecVersionAttributeName ( CloudEventsSpecVersion . V0_2 ) , out val ) ||
48+ dict . TryGetValue ( SpecVersionAttributeName ( CloudEventsSpecVersion . V0_3 ) , out val ) )
4649 {
47- return ( val as string ) == "0.1" ? CloudEventsSpecVersion . V0_1 : CloudEventsSpecVersion . V0_2 ;
50+ return ( val as string ) == "0.1" ? CloudEventsSpecVersion . V0_1 :
51+ ( val as string ) == "0.2" ? CloudEventsSpecVersion . V0_2 :
52+ CloudEventsSpecVersion . V0_3 ;
4853 }
4954
5055 return CloudEventsSpecVersion . Default ;
@@ -60,27 +65,40 @@ public CloudEventsSpecVersion SpecVersion
6065 return ;
6166 }
6267 }
63- else if ( dict . TryGetValue ( SpecVersionAttributeName ( CloudEventsSpecVersion . V0_2 ) , out val ) )
68+ else if ( dict . TryGetValue ( SpecVersionAttributeName ( CloudEventsSpecVersion . V0_2 ) , out val ) )
6469 {
6570 if ( value == CloudEventsSpecVersion . V0_2 && ( val as string ) == "0.2" )
6671 {
6772 return ;
6873 }
6974 }
75+ else if ( dict . TryGetValue ( SpecVersionAttributeName ( CloudEventsSpecVersion . V0_3 ) , out val ) )
76+ {
77+ if ( value == CloudEventsSpecVersion . V0_3 && ( val as string ) == "0.3" )
78+ {
79+ return ;
80+ }
81+ }
7082
7183 // transform to new version
7284 var copy = new Dictionary < string , object > ( dict ) ;
7385 dict . Clear ( ) ;
74- dict [ SpecVersionAttributeName ( value ) ] = value == CloudEventsSpecVersion . V0_1 ? "0.1" : "0.2" ;
86+ dict [ SpecVersionAttributeName ( value ) ] =
87+ value == CloudEventsSpecVersion . V0_1 ? "0.1" :
88+ value == CloudEventsSpecVersion . V0_2 ? "0.2" : "0.3" ;
7589 foreach ( var kv in copy )
7690 {
7791 if ( SpecVersionAttributeName ( currentSpecVersion ) . Equals ( kv . Key ) )
7892 {
7993 continue ;
8094 }
81- if ( ContentTypeAttributeName ( currentSpecVersion ) . Equals ( kv . Key ) )
95+ if ( DataContentTypeAttributeName ( currentSpecVersion ) . Equals ( kv . Key ) )
96+ {
97+ dict [ DataContentTypeAttributeName ( value ) ] = kv . Value ;
98+ }
99+ if ( DataContentEncodingAttributeName ( currentSpecVersion ) . Equals ( kv . Key ) )
82100 {
83- dict [ ContentTypeAttributeName ( value ) ] = kv . Value ;
101+ dict [ DataContentEncodingAttributeName ( value ) ] = kv . Value ;
84102 }
85103 else if ( DataAttributeName ( currentSpecVersion ) . Equals ( kv . Key ) )
86104 {
@@ -98,6 +116,10 @@ public CloudEventsSpecVersion SpecVersion
98116 {
99117 dict [ SourceAttributeName ( value ) ] = kv . Value ;
100118 }
119+ else if ( SubjectAttributeName ( currentSpecVersion ) . Equals ( kv . Key ) )
120+ {
121+ dict [ SubjectAttributeName ( value ) ] = kv . Value ;
122+ }
101123 else if ( TimeAttributeName ( currentSpecVersion ) . Equals ( kv . Key ) )
102124 {
103125 dict [ TimeAttributeName ( value ) ] = kv . Value ;
@@ -110,7 +132,7 @@ public CloudEventsSpecVersion SpecVersion
110132 {
111133 dict [ kv . Key ] = kv . Value ;
112134 }
113- }
135+ }
114136 }
115137 }
116138
@@ -124,9 +146,16 @@ public object this[string key]
124146 }
125147 }
126148
127- public static string ContentTypeAttributeName ( CloudEventsSpecVersion version = CloudEventsSpecVersion . Default )
149+ public static string DataContentTypeAttributeName ( CloudEventsSpecVersion version = CloudEventsSpecVersion . Default )
128150 {
129- return version == CloudEventsSpecVersion . V0_1 ? "contentType" : "contenttype" ;
151+ return version == CloudEventsSpecVersion . V0_1 ? "contentType" :
152+ version == CloudEventsSpecVersion . V0_2 ? "contenttype" :
153+ "datacontenttype" ;
154+ }
155+
156+ public static string DataContentEncodingAttributeName ( CloudEventsSpecVersion version = CloudEventsSpecVersion . Default )
157+ {
158+ return "datacontentencoding" ;
130159 }
131160
132161 public static string DataAttributeName ( CloudEventsSpecVersion version = CloudEventsSpecVersion . Default )
@@ -149,6 +178,11 @@ public static string SourceAttributeName(CloudEventsSpecVersion version = CloudE
149178 return "source" ;
150179 }
151180
181+ public static string SubjectAttributeName ( CloudEventsSpecVersion version = CloudEventsSpecVersion . Default )
182+ {
183+ return "subject" ;
184+ }
185+
152186 public static string SpecVersionAttributeName ( CloudEventsSpecVersion version = CloudEventsSpecVersion . Default )
153187 {
154188 return version == CloudEventsSpecVersion . V0_1 ? "cloudEventsVersion" : "specversion" ;
@@ -288,6 +322,15 @@ internal virtual bool ValidateAndNormalize(string key, ref object value)
288322
289323 throw new InvalidOperationException ( Strings . ErrorSchemaUrlIsNotAUri ) ;
290324 }
325+ else if ( key . Equals ( SubjectAttributeName ( this . SpecVersion ) ) )
326+ {
327+ if ( value is null || value is string )
328+ {
329+ return true ;
330+ }
331+
332+ throw new InvalidOperationException ( Strings . ErrorSchemaUrlIsNotAUri ) ;
333+ }
291334 else if ( key . Equals ( SchemaUrlAttributeName ( this . SpecVersion ) ) )
292335 {
293336 if ( value is null || value is Uri )
@@ -306,7 +349,7 @@ internal virtual bool ValidateAndNormalize(string key, ref object value)
306349
307350 throw new InvalidOperationException ( Strings . ErrorSchemaUrlIsNotAUri ) ;
308351 }
309- else if ( key . Equals ( ContentTypeAttributeName ( this . SpecVersion ) ) )
352+ else if ( key . Equals ( DataContentTypeAttributeName ( this . SpecVersion ) ) )
310353 {
311354 if ( value is null || value is ContentType )
312355 {
@@ -328,6 +371,14 @@ internal virtual bool ValidateAndNormalize(string key, ref object value)
328371
329372 throw new InvalidOperationException ( Strings . ErrorContentTypeIsNotRFC2046 ) ;
330373 }
374+ else if ( key . Equals ( DataContentEncodingAttributeName ( this . SpecVersion ) ) )
375+ {
376+ if ( value is null || value is string )
377+ {
378+ return true ;
379+ }
380+ throw new InvalidOperationException ( Strings . ErrorDataContentEncodingIsNotAString ) ;
381+ }
331382 else if ( key . Equals ( DataAttributeName ( this . SpecVersion ) ) )
332383 {
333384 return true ;
0 commit comments