-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiLink.cs
More file actions
112 lines (88 loc) · 3.65 KB
/
OpenApiLink.cs
File metadata and controls
112 lines (88 loc) · 3.65 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
// 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.Models.Interfaces;
using Microsoft.OpenApi.Writers;
namespace Microsoft.OpenApi.Models
{
/// <summary>
/// Link Object.
/// </summary>
public class OpenApiLink : IOpenApiExtensible, IOpenApiLink
{
/// <inheritdoc/>
public string? OperationRef { get; set; }
/// <inheritdoc/>
public string? OperationId { get; set; }
/// <inheritdoc/>
public IDictionary<string, RuntimeExpressionAnyWrapper>? Parameters { get; set; }
/// <inheritdoc/>
public RuntimeExpressionAnyWrapper? RequestBody { get; set; }
/// <inheritdoc/>
public string? Description { get; set; }
/// <inheritdoc/>
public OpenApiServer? Server { get; set; }
/// <inheritdoc/>
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiLink() { }
/// <summary>
/// Initializes a copy of an <see cref="OpenApiLink"/> object
/// </summary>
internal OpenApiLink(IOpenApiLink link)
{
Utils.CheckArgumentNull(link);
OperationRef = link.OperationRef ?? OperationRef;
OperationId = link.OperationId ?? OperationId;
Parameters = link.Parameters != null ? new Dictionary<string, RuntimeExpressionAnyWrapper>(link.Parameters) : null;
RequestBody = link.RequestBody != null ? new(link.RequestBody) : null;
Description = link.Description ?? Description;
Server = link.Server != null ? new(link.Server) : null;
Extensions = link.Extensions != null ? new Dictionary<string, IOpenApiExtension>(link.Extensions) : null;
}
/// <inheritdoc/>
public void SerializeAsV31(IOpenApiWriter writer)
{
SerializeInternal(writer, (writer, element) => element.SerializeAsV31(writer));
}
/// <inheritdoc/>
public void SerializeAsV3(IOpenApiWriter writer)
{
SerializeInternal(writer, (writer, element) => element.SerializeAsV3(writer));
}
internal void SerializeInternal(IOpenApiWriter writer, Action<IOpenApiWriter, IOpenApiSerializable> callback)
{
Utils.CheckArgumentNull(writer);
writer.WriteStartObject();
// operationRef
writer.WriteProperty(OpenApiConstants.OperationRef, OperationRef);
// operationId
writer.WriteProperty(OpenApiConstants.OperationId, OperationId);
// parameters
writer.WriteOptionalMap(OpenApiConstants.Parameters, Parameters, (w, p) => p.WriteValue(w));
// requestBody
writer.WriteOptionalObject(OpenApiConstants.RequestBody, RequestBody, (w, r) => r.WriteValue(w));
// description
writer.WriteProperty(OpenApiConstants.Description, Description);
// server
writer.WriteOptionalObject(OpenApiConstants.Server, Server, callback);
// specification extensions
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0);
writer.WriteEndObject();
}
/// <inheritdoc/>
public void SerializeAsV2(IOpenApiWriter writer)
{
// Link object does not exist in V2.
}
/// <inheritdoc/>
public IOpenApiLink CreateShallowCopy()
{
return new OpenApiLink(this);
}
}
}