-
Notifications
You must be signed in to change notification settings - Fork 276
Expand file tree
/
Copy pathOpenApiEncoding.cs
More file actions
132 lines (111 loc) · 5.13 KB
/
OpenApiEncoding.cs
File metadata and controls
132 lines (111 loc) · 5.13 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models.Interfaces;
using Microsoft.OpenApi.Writers;
namespace Microsoft.OpenApi.Models
{
/// <summary>
/// ExternalDocs object.
/// </summary>
public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible
{
/// <summary>
/// The Content-Type for encoding a specific property.
/// The value can be a specific media type (e.g. application/json),
/// a wildcard media type (e.g. image/*), or a comma-separated list of the two types.
/// </summary>
public string ContentType { get; set; }
/// <summary>
/// A map allowing additional information to be provided as headers.
/// </summary>
public IDictionary<string, IOpenApiHeader> Headers { get; set; } = new Dictionary<string, IOpenApiHeader>();
/// <summary>
/// Describes how a specific property value will be serialized depending on its type.
/// </summary>
public ParameterStyle? Style { get; set; }
/// <summary>
/// When this is true, property values of type array or object generate separate parameters
/// for each value of the array, or key-value-pair of the map. For other types of properties
/// this property has no effect. When style is form, the default value is true.
/// For all other styles, the default value is false.
/// This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded.
/// </summary>
public bool? Explode { get; set; }
/// <summary>
/// Determines whether the parameter value SHOULD allow reserved characters,
/// as defined by RFC3986 :/?#[]@!$&'()*+,;= to be included without percent-encoding.
/// The default value is false. This property SHALL be ignored
/// if the request body media type is not application/x-www-form-urlencoded.
/// </summary>
public bool? AllowReserved { get; set; }
/// <summary>
/// This object MAY be extended with Specification Extensions.
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiEncoding() { }
/// <summary>
/// Initializes a copy of an <see cref="OpenApiEncoding"/> object
/// </summary>
public OpenApiEncoding(OpenApiEncoding encoding)
{
ContentType = encoding?.ContentType ?? ContentType;
Headers = encoding?.Headers != null ? new Dictionary<string, IOpenApiHeader>(encoding.Headers) : null;
Style = encoding?.Style ?? Style;
Explode = encoding?.Explode ?? Explode;
AllowReserved = encoding?.AllowReserved ?? AllowReserved;
Extensions = encoding?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(encoding.Extensions) : null;
}
/// <summary>
/// Serialize <see cref="OpenApiEncoding"/> to Open Api v3.1
/// </summary>
/// <param name="writer"></param>
public void SerializeAsV31(IOpenApiWriter writer)
{
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1, (writer, element) => element.SerializeAsV31(writer));
}
/// <summary>
/// Serialize <see cref="OpenApiEncoding"/> to Open Api v3.0
/// </summary>
/// <param name="writer"></param>
public void SerializeAsV3(IOpenApiWriter writer)
{
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
}
/// <summary>
/// Serialize <see cref="OpenApiExternalDocs"/> to Open Api v3.0.
/// </summary>
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version,
Action<IOpenApiWriter, IOpenApiSerializable> callback)
{
Utils.CheckArgumentNull(writer);
writer.WriteStartObject();
// contentType
writer.WriteProperty(OpenApiConstants.ContentType, ContentType);
// headers
writer.WriteOptionalMap(OpenApiConstants.Headers, Headers, callback);
// style
writer.WriteProperty(OpenApiConstants.Style, Style?.GetDisplayName());
// explode
writer.WriteProperty(OpenApiConstants.Explode, Explode, false);
// allowReserved
writer.WriteProperty(OpenApiConstants.AllowReserved, AllowReserved, false);
// extensions
writer.WriteExtensions(Extensions, version);
writer.WriteEndObject();
}
/// <summary>
/// Serialize <see cref="OpenApiExternalDocs"/> to Open Api v2.0.
/// </summary>
public void SerializeAsV2(IOpenApiWriter writer)
{
// nothing here
}
}
}