-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathKafkaOperationBinding.cs
More file actions
58 lines (49 loc) · 1.97 KB
/
KafkaOperationBinding.cs
File metadata and controls
58 lines (49 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace ByteBard.AsyncAPI.Bindings.Kafka
{
using System;
using ByteBard.AsyncAPI.Models;
using ByteBard.AsyncAPI.Readers;
using ByteBard.AsyncAPI.Readers.ParseNodes;
using ByteBard.AsyncAPI.Writers;
/// <summary>
/// Binding class for Kafka operations.
/// </summary>
public class KafkaOperationBinding : OperationBinding<KafkaOperationBinding>
{
/// <summary>
/// Id of the consumer group.
/// </summary>
public AsyncApiJsonSchema GroupId { get; set; }
/// <summary>
/// Id of the consumer inside a consumer group.
/// </summary>
public AsyncApiJsonSchema ClientId { get; set; }
public override string BindingKey => "kafka";
protected override FixedFieldMap<KafkaOperationBinding> FixedFieldMap => new()
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "groupId", (a, n) => { a.GroupId = AsyncApiJsonSchemaDeserializer.LoadSchema(n); } },
{ "clientId", (a, n) => { a.ClientId = AsyncApiJsonSchemaDeserializer.LoadSchema(n); } },
};
public override void SerializeV2(IAsyncApiWriter writer)
{
this.SerializeV3(writer);
}
public override void SerializeV3(IAsyncApiWriter writer)
{
this.SerializeProperties(writer);
}
public override void SerializeProperties(IAsyncApiWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteStartObject();
writer.WriteOptionalObject(AsyncApiConstants.GroupId, this.GroupId, (w, h) => h.SerializeV2(w));
writer.WriteOptionalObject(AsyncApiConstants.ClientId, this.ClientId, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion);
writer.WriteEndObject();
}
}
}