Repository navigation
Expand file tree
/
Copy pathAsyncApiInfo.cs
More file actions
128 lines (97 loc) · 4.46 KB
/
Copy pathAsyncApiInfo.cs
File metadata and controls
128 lines (97 loc) · 4.46 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
namespace ByteBard.AsyncAPI.Models
{
using System;
using System.Collections.Generic;
using ByteBard.AsyncAPI.Models.Interfaces;
using ByteBard.AsyncAPI.Writers;
/// <summary>
/// The object provides metadata about the API. The metadata can be used by the clients if needed.
/// </summary>
public class AsyncApiInfo : IAsyncApiSerializable, IAsyncApiExtensible
{
/// <summary>
/// REQUIRED. The title of the application.
/// </summary>
public string Title { get; set; }
/// <summary>
/// REQUIRED Provides the version of the application API (not to be confused with the specification version).
/// </summary>
public string Version { get; set; }
/// <summary>
/// A short description of the application. CommonMark syntax can be used for rich text representation.
/// </summary>
public string Description { get; set; }
/// <summary>
/// A URL to the Terms of Service for the API. This MUST be in the form of an absolute URL.
/// </summary>
public Uri TermsOfService { get; set; }
/// <summary>
/// The contact information for the exposed API.
/// </summary>
public AsyncApiContact Contact { get; set; }
/// <summary>
/// The license information for the exposed API.
/// </summary>
public AsyncApiLicense License { get; set; }
/// <summary>
/// a list of tags used by the specification with additional metadata. Each tag name in the list MUST be unique.
/// </summary>
public IList<AsyncApiTag> Tags { get; set; } = new List<AsyncApiTag>();
/// <summary>
/// additional external documentation.
/// </summary>
public AsyncApiExternalDocumentation ExternalDocs { 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();
// title
writer.WriteRequiredProperty(AsyncApiConstants.Title, this.Title);
// version
writer.WriteOptionalProperty(AsyncApiConstants.Version, this.Version);
// description
writer.WriteOptionalProperty(AsyncApiConstants.Description, this.Description);
// termsOfService
writer.WriteOptionalProperty(AsyncApiConstants.TermsOfService, this.TermsOfService?.OriginalString);
// contact object
writer.WriteOptionalObject(AsyncApiConstants.Contact, this.Contact, (w, c) => c.SerializeV2(w));
// license object
writer.WriteOptionalObject(AsyncApiConstants.License, this.License, (w, l) => l.SerializeV2(w));
// specification extensions
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
public void SerializeV3(IAsyncApiWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteStartObject();
// title
writer.WriteRequiredProperty(AsyncApiConstants.Title, this.Title);
// version
writer.WriteOptionalProperty(AsyncApiConstants.Version, this.Version);
// description
writer.WriteOptionalProperty(AsyncApiConstants.Description, this.Description);
// termsOfService
writer.WriteOptionalProperty(AsyncApiConstants.TermsOfService, this.TermsOfService?.OriginalString);
// contact object
writer.WriteOptionalObject(AsyncApiConstants.Contact, this.Contact, (w, c) => c.SerializeV3(w));
// license object
writer.WriteOptionalObject(AsyncApiConstants.License, this.License, (w, l) => l.SerializeV3(w));
// tags
writer.WriteOptionalCollection(AsyncApiConstants.Tags, this.Tags, (w, t) => t.SerializeV3(w));
// external docs
writer.WriteOptionalObject(AsyncApiConstants.ExternalDocs, this.ExternalDocs, (w, e) => e.SerializeV3(w));
// specification extensions
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
}
}