Skip to content

Commit 9146269

Browse files
committed
feat: Added nullable enable to OpenApiMediaType.
1 parent 2deb4aa commit 9146269

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Microsoft.OpenApi/Models/OpenApiMediaType.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
using Microsoft.OpenApi.Interfaces;
1010
using Microsoft.OpenApi.Writers;
1111

12+
#nullable enable
13+
1214
namespace Microsoft.OpenApi.Models
1315
{
1416
/// <summary>
1517
/// Media Type Object.
1618
/// </summary>
1719
public class OpenApiMediaType : IOpenApiSerializable, IOpenApiExtensible
1820
{
19-
private JsonSchema _schema;
21+
private JsonSchema? _schema;
2022

2123
/// <summary>
2224
/// The schema defining the type used for the request body.
2325
/// </summary>
24-
public virtual JsonSchema Schema
26+
public virtual JsonSchema? Schema
2527
{
2628
get => _schema;
2729
set => _schema = value;
@@ -31,26 +33,26 @@ public virtual JsonSchema Schema
3133
/// Example of the media type.
3234
/// The example object SHOULD be in the correct format as specified by the media type.
3335
/// </summary>
34-
public OpenApiAny Example { get; set; }
36+
public OpenApiAny? Example { get; set; }
3537

3638
/// <summary>
3739
/// Examples of the media type.
3840
/// Each example object SHOULD match the media type and specified schema if present.
3941
/// </summary>
40-
public IDictionary<string, OpenApiExample> Examples { get; set; } = new Dictionary<string, OpenApiExample>();
42+
public IDictionary<string, OpenApiExample>? Examples { get; set; } = new Dictionary<string, OpenApiExample>();
4143

4244
/// <summary>
4345
/// A map between a property name and its encoding information.
4446
/// The key, being the property name, MUST exist in the schema as a property.
4547
/// The encoding object SHALL only apply to requestBody objects
4648
/// when the media type is multipart or application/x-www-form-urlencoded.
4749
/// </summary>
48-
public IDictionary<string, OpenApiEncoding> Encoding { get; set; } = new Dictionary<string, OpenApiEncoding>();
50+
public IDictionary<string, OpenApiEncoding>? Encoding { get; set; } = new Dictionary<string, OpenApiEncoding>();
4951

5052
/// <summary>
5153
/// Serialize <see cref="OpenApiExternalDocs"/> to Open Api v3.0.
5254
/// </summary>
53-
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
55+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
5456

5557
/// <summary>
5658
/// Parameterless constructor
@@ -60,7 +62,7 @@ public OpenApiMediaType() { }
6062
/// <summary>
6163
/// Initializes a copy of an <see cref="OpenApiMediaType"/> object
6264
/// </summary>
63-
public OpenApiMediaType(OpenApiMediaType mediaType)
65+
public OpenApiMediaType(OpenApiMediaType? mediaType)
6466
{
6567
Schema = mediaType?.Schema != null ? JsonNodeCloneHelper.CloneJsonSchema(mediaType.Schema) : null;
6668
Example = mediaType?.Example != null ? JsonNodeCloneHelper.Clone(mediaType.Example) : null;

0 commit comments

Comments
 (0)