3
3
namespace LEGO . AsyncAPI . Models
4
4
{
5
5
using System . Collections . Generic ;
6
+ using System . Linq ;
6
7
using LEGO . AsyncAPI . Writers ;
7
8
8
9
public class AvroEnum : AvroSchema
9
10
{
10
11
public string Type { get ; } = "enum" ;
11
12
12
13
public string Name { get ; set ; }
13
-
14
+
14
15
public string Namespace { get ; set ; }
15
16
16
17
public string Doc { get ; set ; }
@@ -21,16 +22,36 @@ public class AvroEnum : AvroSchema
21
22
22
23
public string Default { get ; set ; }
23
24
25
+ /// <summary>
26
+ /// A map of properties not in the schema, but added as additional metadata.
27
+ /// </summary>
28
+ public IDictionary < string , AvroSchema > Metadata { get ; set ; } = new Dictionary < string , AvroSchema > ( ) ;
29
+
24
30
public override void SerializeV2 ( IAsyncApiWriter writer )
25
31
{
26
32
writer . WriteStartObject ( ) ;
27
33
writer . WriteOptionalProperty ( "type" , this . Type ) ;
28
34
writer . WriteRequiredProperty ( "name" , this . Name ) ;
29
- writer . WriteRequiredProperty ( "namespace" , this . Namespace ) ;
35
+ writer . WriteOptionalProperty ( "namespace" , this . Namespace ) ;
30
36
writer . WriteOptionalCollection ( "aliases" , this . Aliases , ( w , s ) => w . WriteValue ( s ) ) ;
31
37
writer . WriteOptionalProperty ( "doc" , this . Doc ) ;
32
38
writer . WriteRequiredCollection ( "symbols" , this . Symbols , ( w , s ) => w . WriteValue ( s ) ) ;
33
39
writer . WriteRequiredProperty ( "default" , this . Default ) ;
40
+ if ( this . Metadata . Any ( ) )
41
+ {
42
+ foreach ( var item in this . Metadata )
43
+ {
44
+ writer . WritePropertyName ( item . Key ) ;
45
+ if ( item . Value == null )
46
+ {
47
+ writer . WriteNull ( ) ;
48
+ }
49
+ else
50
+ {
51
+ item . Value . SerializeV2 ( writer ) ;
52
+ }
53
+ }
54
+ }
34
55
writer . WriteEndObject ( ) ;
35
56
}
36
57
}
0 commit comments