-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathHttpMessageBinding.cs
More file actions
48 lines (40 loc) · 1.65 KB
/
HttpMessageBinding.cs
File metadata and controls
48 lines (40 loc) · 1.65 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
// Copyright (c) The LEGO Group. All rights reserved.
namespace LEGO.AsyncAPI.Bindings.Http
{
using System;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
using LEGO.AsyncAPI.Writers;
/// <summary>
/// Binding class for http messaging channels.
/// </summary>
public class HttpMessageBinding : MessageBinding<HttpMessageBinding>
{
/// <summary>
/// A Schema object containing the definitions for HTTP-specific headers. This schema MUST be of type object and have a properties key.
/// </summary>
public AsyncApiJsonSchema Headers { get; set; }
/// <summary>
/// Serialize to AsyncAPI V2 document without using reference.
/// </summary>
public override void SerializeProperties(IAsyncApiWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteStartObject();
writer.WriteOptionalObject(AsyncApiConstants.Headers, this.Headers, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion);
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
public override string BindingKey => "http";
protected override FixedFieldMap<HttpMessageBinding> FixedFieldMap => new()
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "headers", (a, n) => { a.Headers = AsyncApiSchemaDeserializer.LoadSchema(n); } },
};
}
}