Repository navigation
Expand file tree
/
Copy pathAsyncApiReference.cs
More file actions
75 lines (63 loc) · 2.21 KB
/
Copy pathAsyncApiReference.cs
File metadata and controls
75 lines (63 loc) · 2.21 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
// Copyright (c) The LEGO Group. All rights reserved.
namespace LEGO.AsyncAPI.Models
{
using System;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;
/// <summary>
/// A simple object to allow referencing other components in the specification, internally and externally.
/// </summary>
public class AsyncApiReference : IAsyncApiSerializable
{
/// <summary>
/// Gets or sets the element type referenced.
/// </summary>
public ReferenceType? Type { get; set; }
/// <summary>
/// Gets or sets the identifier of the reusable component of one particular ReferenceType.
/// </summary>
public string Id { get; set; }
/// <summary>
/// Gets or sets the AsyncApiDocument that is hosting the AsyncApiReference instance. This is used to enable dereferencing the reference.
/// </summary>
public AsyncApiDocument HostDocument { get; set; } = null;
/// <summary>
/// Gets the full reference string for v2.3.
/// </summary>
public string Reference
{
get
{
if (!this.Type.HasValue)
{
throw new ArgumentNullException(nameof(this.Type));
}
return "#/components/" + this.Type.GetDisplayName() + "/" + this.Id;
}
}
/// <summary>
/// Serialize <see cref="AsyncApiReference"/> to Async Api v2.4.
/// </summary>
public void SerializeV2(IAsyncApiWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
if (this.Type == ReferenceType.SecurityScheme)
{
// Write the string as property name
writer.WritePropertyName(this.Reference);
return;
}
writer.WriteStartObject();
// $ref
writer.WriteOptionalProperty(AsyncApiConstants.DollarRef, this.Reference);
writer.WriteEndObject();
}
public void Write(IAsyncApiWriter writer)
{
this.SerializeV2(writer);
}
}
}