Repository navigation
Expand file tree
/
Copy pathAsyncApiServer.cs
More file actions
140 lines (103 loc) · 5.98 KB
/
Copy pathAsyncApiServer.cs
File metadata and controls
140 lines (103 loc) · 5.98 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
namespace ByteBard.AsyncAPI.Models
{
using System.Collections.Generic;
using ByteBard.AsyncAPI.Models.Interfaces;
using ByteBard.AsyncAPI.Writers;
public class AsyncApiServer : IAsyncApiSerializable, IAsyncApiExtensible
{
/// <summary>
/// REQUIRED. The server host name. It MAY include the port. This field supports Server Variables. Variable substitutions will be made when a variable is named in {braces}.
/// </summary>
public virtual string Host { get; set; }
/// <summary>
/// The path to a resource in the host. This field supports Server Variables. Variable substitutions will be made when a variable is named in {braces}.
/// </summary>
public virtual string PathName { get; set; }
/// <summary>
/// REQUIRED. The protocol this URL supports for connection.
/// </summary>
public virtual string Protocol { get; set; }
/// <summary>
/// The version of the protocol used for connection. For instance: AMQP 0.9.1, HTTP 2.0, Kafka 1.0.0, etc.
/// </summary>
public virtual string ProtocolVersion { get; set; }
/// <summary>
/// an optional string describing the host designated by the URL.
/// </summary>
public virtual string Description { get; set; }
/// <summary>
/// A human-friendly title for the server.
/// </summary>
public virtual string Title { get; set; }
/// <summary>
/// A short summary of the server.
/// </summary>
public virtual string Summary { get; set; }
/// <summary>
/// a map between a variable name and its value. The value is used for substitution in the server's URL template.
/// </summary>
public virtual IDictionary<string, AsyncApiServerVariable> Variables { get; set; } = new Dictionary<string, AsyncApiServerVariable>();
/// <summary>
/// A declaration of which security schemes can be used with this server. The list of values includes alternative security scheme objects that can be used. Only one of the security scheme objects need to be satisfied to authorize a connection or operation.
/// </summary>
/// <remarks>
/// The name used for each property MUST correspond to a security scheme declared in the Security Schemes under the Components Object.
/// </remarks>
public virtual IList<AsyncApiSecurityScheme> Security { get; set; } = new List<AsyncApiSecurityScheme>();
/// <summary>
/// A list of tags for logical grouping and categorization of servers.
/// </summary>
public virtual IList<AsyncApiTag> Tags { get; set; } = new List<AsyncApiTag>();
/// <summary>
/// Additional external documentation for this server.
/// </summary>
public virtual AsyncApiExternalDocumentation ExternalDocs { get; set; }
/// <summary>
/// a map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the server.
/// </summary>
public virtual AsyncApiBindings<IServerBinding> Bindings { get; set; } = new AsyncApiBindings<IServerBinding>();
/// <inheritdoc/>
public virtual IDictionary<string, IAsyncApiExtension> Extensions { get; set; } = new Dictionary<string, IAsyncApiExtension>();
public virtual void SerializeV2(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteRequiredProperty(AsyncApiConstants.Url, this.GenerateServerUrl());
writer.WriteRequiredProperty(AsyncApiConstants.Protocol, this.Protocol);
writer.WriteOptionalProperty(AsyncApiConstants.ProtocolVersion, this.ProtocolVersion);
writer.WriteOptionalProperty(AsyncApiConstants.Description, this.Description);
writer.WriteOptionalMap(AsyncApiConstants.Variables, this.Variables, (w, v) => v.SerializeV2(w));
writer.WriteOptionalCollection(AsyncApiConstants.Security, this.Security, (w, s) => this.SerializeAsSecurityRequirement(s, w));
writer.WriteOptionalCollection(AsyncApiConstants.Tags, this.Tags, (w, s) => s.SerializeV2(w));
writer.WriteOptionalObject(AsyncApiConstants.Bindings, this.Bindings, (w, t) => t.SerializeV2(w));
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
private void SerializeAsSecurityRequirement(AsyncApiSecurityScheme scheme, IAsyncApiWriter w)
{
if (scheme is not AsyncApiSecuritySchemeReference schemeReference)
{
throw new AsyncApiWriterException("Cannot serialize securityScheme as V2 as it is not a Reference.");
}
schemeReference.SerializeAsSecurityRequirement(w);
}
public virtual void SerializeV3(IAsyncApiWriter writer)
{
writer.WriteStartObject();
writer.WriteRequiredProperty(AsyncApiConstants.Host, this.Host);
writer.WriteRequiredProperty(AsyncApiConstants.Protocol, this.Protocol);
writer.WriteOptionalProperty(AsyncApiConstants.ProtocolVersion, this.ProtocolVersion);
writer.WriteOptionalProperty(AsyncApiConstants.PathName, this.PathName);
writer.WriteOptionalProperty(AsyncApiConstants.Description, this.Description);
writer.WriteOptionalMap(AsyncApiConstants.Variables, this.Variables, (w, v) => v.SerializeV3(w));
writer.WriteOptionalCollection(AsyncApiConstants.Security, this.Security, (w, s) => s.SerializeV3(w));
writer.WriteOptionalCollection(AsyncApiConstants.Tags, this.Tags, (w, s) => s.SerializeV3(w));
writer.WriteOptionalObject(AsyncApiConstants.Bindings, this.Bindings, (w, t) => t.SerializeV3(w));
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
private string GenerateServerUrl()
{
return $"{this.Host}{this.PathName}";
}
}
}