-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathAsyncApiMessageExample.cs
More file actions
54 lines (46 loc) · 2.01 KB
/
Copy pathAsyncApiMessageExample.cs
File metadata and controls
54 lines (46 loc) · 2.01 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
// Copyright (c) The LEGO Group. All rights reserved.
namespace LEGO.AsyncAPI.Models
{
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;
/// <summary>
/// Represents an example of a Message Object and MUST contain either headers and/or payload fields.
/// </summary>
public class AsyncApiMessageExample : IAsyncApiExtensible, IAsyncApiSerializable
{
/// <summary>
/// Gets or sets the value of this field MUST validate against the Message Object's headers field.
/// </summary>
public IDictionary<string, AsyncApiAny> Headers { get; set; } = new Dictionary<string, AsyncApiAny>();
/// <summary>
/// Gets or sets the value of this field MUST validate against the Message Object's payload field.
/// </summary>
public AsyncApiAny Payload { get; set; }
/// <summary>
/// a machine-friendly name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// a short summary of what the example is about.
/// </summary>
public string Summary { get; set; }
/// <inheritdoc/>
public IDictionary<string, IAsyncApiExtension> Extensions { get; set; } = new Dictionary<string, IAsyncApiExtension>();
public void SerializeV2(IAsyncApiWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteStartObject();
writer.WriteOptionalProperty(AsyncApiConstants.Name, this.Name);
writer.WriteOptionalProperty(AsyncApiConstants.Summary, this.Summary);
writer.WriteOptionalMap(AsyncApiConstants.Headers, this.Headers, (w, h) => w.WriteAny(h));
writer.WriteOptionalObject(AsyncApiConstants.Payload, this.Payload, (w, p) => w.WriteAny(p));
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
}
}