-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiLicense.cs
More file actions
95 lines (81 loc) · 3.14 KB
/
OpenApiLicense.cs
File metadata and controls
95 lines (81 loc) · 3.14 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;
namespace Microsoft.OpenApi.Models
{
/// <summary>
/// License Object.
/// </summary>
public class OpenApiLicense : IOpenApiSerializable, IOpenApiExtensible
{
/// <summary>
/// REQUIRED. The license name used for the API.
/// </summary>
public string? Name { get; set; }
/// <summary>
/// An SPDX license expression for the API. The identifier field is mutually exclusive of the url field.
/// </summary>
public string? Identifier { get; set; }
/// <summary>
/// The URL pointing to the contact information. MUST be in the format of a URL.
/// </summary>
public Uri? Url { get; set; }
/// <summary>
/// This object MAY be extended with Specification Extensions.
/// </summary>
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiLicense() { }
/// <summary>
/// Initializes a copy of an <see cref="OpenApiLicense"/> object
/// </summary>
public OpenApiLicense(OpenApiLicense license)
{
Name = license?.Name ?? Name;
Identifier = license?.Identifier ?? Identifier;
Url = license?.Url != null ? new Uri(license.Url.OriginalString, UriKind.RelativeOrAbsolute) : null;
Extensions = license?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(license.Extensions) : null;
}
/// <summary>
/// Serialize <see cref="OpenApiLicense"/> to Open Api v3.1
/// </summary>
public void SerializeAsV31(IOpenApiWriter writer)
{
WriteInternal(writer, OpenApiSpecVersion.OpenApi3_1);
writer.WriteProperty(OpenApiConstants.Identifier, Identifier);
writer.WriteEndObject();
}
/// <summary>
/// Serialize <see cref="OpenApiLicense"/> to Open Api v3.0
/// </summary>
public void SerializeAsV3(IOpenApiWriter writer)
{
WriteInternal(writer, OpenApiSpecVersion.OpenApi3_0);
writer.WriteEndObject();
}
/// <summary>
/// Serialize <see cref="OpenApiLicense"/> to Open Api v2.0
/// </summary>
public void SerializeAsV2(IOpenApiWriter writer)
{
WriteInternal(writer, OpenApiSpecVersion.OpenApi2_0);
writer.WriteEndObject();
}
private void WriteInternal(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
{
Utils.CheckArgumentNull(writer);
writer.WriteStartObject();
// name
writer.WriteProperty(OpenApiConstants.Name, Name);
// url
writer.WriteProperty(OpenApiConstants.Url, Url?.OriginalString);
// specification extensions
writer.WriteExtensions(Extensions, specVersion);
}
}
}