Skip to content

Commit c06a9f1

Browse files
committed
feat: Added nullable enable to OpenApiComponents.
1 parent 4afdd15 commit c06a9f1

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/Microsoft.OpenApi/Models/OpenApiComponents.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.OpenApi.Interfaces;
99
using Microsoft.OpenApi.Writers;
1010

11+
#nullable enable
1112

1213
namespace Microsoft.OpenApi.Models
1314
{
@@ -19,60 +20,60 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
1920
/// <summary>
2021
/// An object to hold reusable <see cref="JsonSchema"/> Objects.
2122
/// </summary>
22-
public IDictionary<string, JsonSchema> Schemas { get; set; } = new Dictionary<string, JsonSchema>();
23+
public IDictionary<string, JsonSchema>? Schemas { get; set; } = new Dictionary<string, JsonSchema>();
2324

2425
/// <summary>
2526
/// An object to hold reusable <see cref="OpenApiResponse"/> Objects.
2627
/// </summary>
27-
public virtual IDictionary<string, OpenApiResponse> Responses { get; set; } = new Dictionary<string, OpenApiResponse>();
28+
public virtual IDictionary<string, OpenApiResponse>? Responses { get; set; } = new Dictionary<string, OpenApiResponse>();
2829

2930
/// <summary>
3031
/// An object to hold reusable <see cref="OpenApiParameter"/> Objects.
3132
/// </summary>
32-
public virtual IDictionary<string, OpenApiParameter> Parameters { get; set; } =
33+
public virtual IDictionary<string, OpenApiParameter>? Parameters { get; set; } =
3334
new Dictionary<string, OpenApiParameter>();
3435

3536
/// <summary>
3637
/// An object to hold reusable <see cref="OpenApiExample"/> Objects.
3738
/// </summary>
38-
public virtual IDictionary<string, OpenApiExample> Examples { get; set; } = new Dictionary<string, OpenApiExample>();
39+
public virtual IDictionary<string, OpenApiExample>? Examples { get; set; } = new Dictionary<string, OpenApiExample>();
3940

4041
/// <summary>
4142
/// An object to hold reusable <see cref="OpenApiRequestBody"/> Objects.
4243
/// </summary>
43-
public virtual IDictionary<string, OpenApiRequestBody> RequestBodies { get; set; } =
44+
public virtual IDictionary<string, OpenApiRequestBody>? RequestBodies { get; set; } =
4445
new Dictionary<string, OpenApiRequestBody>();
4546

4647
/// <summary>
4748
/// An object to hold reusable <see cref="OpenApiHeader"/> Objects.
4849
/// </summary>
49-
public virtual IDictionary<string, OpenApiHeader> Headers { get; set; } = new Dictionary<string, OpenApiHeader>();
50+
public virtual IDictionary<string, OpenApiHeader>? Headers { get; set; } = new Dictionary<string, OpenApiHeader>();
5051

5152
/// <summary>
5253
/// An object to hold reusable <see cref="OpenApiSecurityScheme"/> Objects.
5354
/// </summary>
54-
public virtual IDictionary<string, OpenApiSecurityScheme> SecuritySchemes { get; set; } =
55+
public virtual IDictionary<string, OpenApiSecurityScheme>? SecuritySchemes { get; set; } =
5556
new Dictionary<string, OpenApiSecurityScheme>();
5657

5758
/// <summary>
5859
/// An object to hold reusable <see cref="OpenApiLink"/> Objects.
5960
/// </summary>
60-
public virtual IDictionary<string, OpenApiLink> Links { get; set; } = new Dictionary<string, OpenApiLink>();
61+
public virtual IDictionary<string, OpenApiLink>? Links { get; set; } = new Dictionary<string, OpenApiLink>();
6162

6263
/// <summary>
6364
/// An object to hold reusable <see cref="OpenApiCallback"/> Objects.
6465
/// </summary>
65-
public virtual IDictionary<string, OpenApiCallback> Callbacks { get; set; } = new Dictionary<string, OpenApiCallback>();
66+
public virtual IDictionary<string, OpenApiCallback>? Callbacks { get; set; } = new Dictionary<string, OpenApiCallback>();
6667

6768
/// <summary>
6869
/// An object to hold reusable <see cref="OpenApiPathItem"/> Object.
6970
/// </summary>
70-
public virtual IDictionary<string, OpenApiPathItem> PathItems { get; set; } = new Dictionary<string, OpenApiPathItem>();
71+
public virtual IDictionary<string, OpenApiPathItem>? PathItems { get; set; } = new Dictionary<string, OpenApiPathItem>();
7172

7273
/// <summary>
7374
/// This object MAY be extended with Specification Extensions.
7475
/// </summary>
75-
public virtual IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
76+
public virtual IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
7677

7778
/// <summary>
7879
/// Parameter-less constructor
@@ -82,7 +83,7 @@ public OpenApiComponents() { }
8283
/// <summary>
8384
/// Initializes a copy of an <see cref="OpenApiComponents"/> object
8485
/// </summary>
85-
public OpenApiComponents(OpenApiComponents components)
86+
public OpenApiComponents(OpenApiComponents? components)
8687
{
8788
Schemas = components?.Schemas != null ? new Dictionary<string, JsonSchema>(components.Schemas) : null;
8889
Responses = components?.Responses != null ? new Dictionary<string, OpenApiResponse>(components.Responses) : null;

test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public void RemoveAnyOfAndOneOfFromSchema()
5959
var walker = new OpenApiWalker(powerShellFormatter);
6060
walker.Walk(openApiDocument);
6161

62-
var testSchema = openApiDocument.Components.Schemas["TestSchema"];
63-
var averageAudioDegradationProperty = testSchema.GetProperties()?.GetValueOrDefault("averageAudioDegradation");
64-
var defaultPriceProperty = testSchema.GetProperties()?.GetValueOrDefault("defaultPrice");
62+
var testSchema = openApiDocument.Components.Schemas?["TestSchema"];
63+
var averageAudioDegradationProperty = testSchema?.GetProperties()?.GetValueOrDefault("averageAudioDegradation");
64+
var defaultPriceProperty = testSchema?.GetProperties()?.GetValueOrDefault("defaultPrice");
6565

6666
// Assert
6767
Assert.Null(averageAudioDegradationProperty?.GetAnyOf());
@@ -71,7 +71,7 @@ public void RemoveAnyOfAndOneOfFromSchema()
7171
Assert.Null(defaultPriceProperty?.GetOneOf());
7272
Assert.Equal(SchemaValueType.Number, defaultPriceProperty?.GetJsonType());
7373
Assert.Equal("double", defaultPriceProperty?.GetFormat()?.Key);
74-
Assert.NotNull(testSchema.GetAdditionalProperties());
74+
Assert.NotNull(testSchema?.GetAdditionalProperties());
7575
}
7676

7777
[Fact]

0 commit comments

Comments
 (0)