-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathKafkaMessageBinding.cs
More file actions
78 lines (65 loc) · 3.19 KB
/
KafkaMessageBinding.cs
File metadata and controls
78 lines (65 loc) · 3.19 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 messages.
/// </summary>
public class KafkaMessageBinding : MessageBinding<KafkaMessageBinding>
{
/// <summary>
/// The message key. NOTE: You can also use the <a href="https://www.asyncapi.com/docs/reference/specification/v2.4.0#referenceObject">reference object</a> way.
/// </summary>
public AsyncApiJsonSchema Key { get; set; }
/// <summary>
/// If a Schema Registry is used when performing this operation, tells where the id of schema is stored (e.g. header or payload).
/// </summary>
public string SchemaIdLocation { get; set; }
/// <summary>
/// Number of bytes or vendor specific values when schema id is encoded in payload (e.g confluent/ apicurio-legacy / apicurio-new).
/// </summary>
public string SchemaIdPayloadEncoding { get; set; }
/// <summary>
/// Freeform string for any naming strategy class to use. Clients should default to the vendor default if not supplied.
/// </summary>
public string SchemaLookupStrategy { get; set; }
/// <summary>
/// The version of this binding. If omitted, "latest" MUST be assumed.
/// </summary>
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.Key, this.Key, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.SchemaIdLocation, this.SchemaIdLocation);
writer.WriteOptionalProperty(AsyncApiConstants.SchemaIdPayloadEncoding, this.SchemaIdPayloadEncoding);
writer.WriteOptionalProperty(AsyncApiConstants.SchemaLookupStrategy, this.SchemaLookupStrategy);
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion);
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
public override string BindingKey => "kafka";
protected override FixedFieldMap<KafkaMessageBinding> FixedFieldMap => new()
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "key", (a, n) => { a.Key = AsyncApiJsonSchemaDeserializer.LoadSchema(n); } },
{ "schemaIdLocation", (a, n) => { a.SchemaIdLocation = n.GetScalarValue(); } },
{ "schemaIdPayloadEncoding", (a, n) => { a.SchemaIdPayloadEncoding = n.GetScalarValue(); } },
{ "schemaLookupStrategy", (a, n) => { a.SchemaLookupStrategy = n.GetScalarValue(); } },
};
}
}