Skip to content

Commit 6fff3c5

Browse files
committed
chore: remove default collection initialization across all models; clean up and fix tests
1 parent 08cc754 commit 6fff3c5

File tree

61 files changed

+269
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+269
-238
lines changed

src/Microsoft.OpenApi/Models/OpenApiCallback.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ namespace Microsoft.OpenApi.Models
1313
/// <summary>
1414
/// Callback Object: A map of possible out-of band callbacks related to the parent operation.
1515
/// </summary>
16-
public class OpenApiCallback : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiCallback
16+
public class OpenApiCallback : IOpenApiExtensible, IOpenApiCallback
1717
{
1818
/// <inheritdoc/>
1919
public Dictionary<RuntimeExpression, IOpenApiPathItem>? PathItems { get; set; }
20-
= [];
2120

2221

2322
/// <summary>
2423
/// This object MAY be extended with Specification Extensions.
2524
/// </summary>
26-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
25+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
2726

2827
/// <summary>
2928
/// Parameter-less constructor

src/Microsoft.OpenApi/Models/OpenApiComponents.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,60 +19,57 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
1919
/// <summary>
2020
/// An object to hold reusable <see cref="IOpenApiSchema"/> Objects.
2121
/// </summary>
22-
public IDictionary<string, IOpenApiSchema>? Schemas { get; set; } = new Dictionary<string, IOpenApiSchema>();
22+
public IDictionary<string, IOpenApiSchema>? Schemas { get; set; }
2323

2424
/// <summary>
2525
/// An object to hold reusable <see cref="IOpenApiResponse"/> Objects.
2626
/// </summary>
27-
public IDictionary<string, IOpenApiResponse>? Responses { get; set; } = new Dictionary<string, IOpenApiResponse>();
27+
public IDictionary<string, IOpenApiResponse>? Responses { get; set; }
2828

2929
/// <summary>
3030
/// An object to hold reusable <see cref="IOpenApiParameter"/> Objects.
3131
/// </summary>
32-
public IDictionary<string, IOpenApiParameter>? Parameters { get; set; } =
33-
new Dictionary<string, IOpenApiParameter>();
32+
public IDictionary<string, IOpenApiParameter>? Parameters { get; set; }
3433

3534
/// <summary>
3635
/// An object to hold reusable <see cref="OpenApiExample"/> Objects.
3736
/// </summary>
38-
public IDictionary<string, IOpenApiExample>? Examples { get; set; } = new Dictionary<string, IOpenApiExample>();
37+
public IDictionary<string, IOpenApiExample>? Examples { get; set; }
3938

4039
/// <summary>
4140
/// An object to hold reusable <see cref="IOpenApiRequestBody"/> Objects.
4241
/// </summary>
43-
public IDictionary<string, IOpenApiRequestBody>? RequestBodies { get; set; } =
44-
new Dictionary<string, IOpenApiRequestBody>();
42+
public IDictionary<string, IOpenApiRequestBody>? RequestBodies { get; set; }
4543

4644
/// <summary>
4745
/// An object to hold reusable <see cref="IOpenApiHeader"/> Objects.
4846
/// </summary>
49-
public IDictionary<string, IOpenApiHeader>? Headers { get; set; } = new Dictionary<string, IOpenApiHeader>();
47+
public IDictionary<string, IOpenApiHeader>? Headers { get; set; }
5048

5149
/// <summary>
5250
/// An object to hold reusable <see cref="IOpenApiSecurityScheme"/> Objects.
5351
/// </summary>
54-
public IDictionary<string, IOpenApiSecurityScheme>? SecuritySchemes { get; set; } =
55-
new Dictionary<string, IOpenApiSecurityScheme>();
52+
public IDictionary<string, IOpenApiSecurityScheme>? SecuritySchemes { get; set; }
5653

5754
/// <summary>
5855
/// An object to hold reusable <see cref="IOpenApiLink"/> Objects.
5956
/// </summary>
60-
public IDictionary<string, IOpenApiLink>? Links { get; set; } = new Dictionary<string, IOpenApiLink>();
57+
public IDictionary<string, IOpenApiLink>? Links { get; set; }
6158

6259
/// <summary>
6360
/// An object to hold reusable <see cref="OpenApiCallback"/> Objects.
6461
/// </summary>
65-
public IDictionary<string, IOpenApiCallback>? Callbacks { get; set; } = new Dictionary<string, IOpenApiCallback>();
62+
public IDictionary<string, IOpenApiCallback>? Callbacks { get; set; }
6663

6764
/// <summary>
6865
/// An object to hold reusable <see cref="IOpenApiPathItem"/> Object.
6966
/// </summary>
70-
public IDictionary<string, IOpenApiPathItem>? PathItems { get; set; } = new Dictionary<string, IOpenApiPathItem>();
67+
public IDictionary<string, IOpenApiPathItem>? PathItems { get; set; }
7168

7269
/// <summary>
7370
/// This object MAY be extended with Specification Extensions.
7471
/// </summary>
75-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
72+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
7673

7774
/// <summary>
7875
/// Parameter-less constructor

src/Microsoft.OpenApi/Models/OpenApiContact.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible
3232
/// <summary>
3333
/// This object MAY be extended with Specification Extensions.
3434
/// </summary>
35-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
35+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
3636

3737
/// <summary>
3838
/// Parameter-less constructor

src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class OpenApiDiscriminator : IOpenApiSerializable, IOpenApiExtensible
2121
/// <summary>
2222
/// An object to hold mappings between payload values and schema names or references.
2323
/// </summary>
24-
public IDictionary<string, OpenApiSchemaReference>? Mapping { get; set; } = new Dictionary<string, OpenApiSchemaReference>();
24+
public IDictionary<string, OpenApiSchemaReference>? Mapping { get; set; }
2525

2626
/// <summary>
2727
/// This object MAY be extended with Specification Extensions.
2828
/// </summary>
29-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
29+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
3030

3131
/// <summary>
3232
/// Parameter-less constructor
@@ -81,13 +81,7 @@ private void SerializeInternal(IOpenApiWriter writer)
8181
writer.WriteProperty(OpenApiConstants.PropertyName, PropertyName);
8282

8383
// mapping
84-
writer.WriteOptionalMap(OpenApiConstants.Mapping, Mapping, (w, s) =>
85-
{
86-
if (!string.IsNullOrEmpty(s.Reference.ReferenceV3) && s.Reference.ReferenceV3 is not null)
87-
{
88-
w.WriteValue(s.Reference.ReferenceV3);
89-
}
90-
});
84+
writer.WriteOptionalMap(OpenApiConstants.Mapping, Mapping, (w, s) => w.WriteValue(s));
9185
}
9286

9387
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void RegisterComponents()
4949
/// <summary>
5050
/// An array of Server Objects, which provide connectivity information to a target server.
5151
/// </summary>
52-
public IList<OpenApiServer>? Servers { get; set; } = new List<OpenApiServer>();
52+
public IList<OpenApiServer>? Servers { get; set; }
5353

5454
/// <summary>
5555
/// REQUIRED. The available paths and operations for the API.
@@ -61,7 +61,7 @@ public void RegisterComponents()
6161
/// A map of requests initiated other than by an API call, for example by an out of band registration.
6262
/// The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses
6363
/// </summary>
64-
public IDictionary<string, IOpenApiPathItem>? Webhooks { get; set; } = new Dictionary<string, IOpenApiPathItem>();
64+
public IDictionary<string, IOpenApiPathItem>? Webhooks { get; set; }
6565

6666
/// <summary>
6767
/// An element to hold various schemas for the specification.
@@ -71,8 +71,7 @@ public void RegisterComponents()
7171
/// <summary>
7272
/// A declaration of which security mechanisms can be used across the API.
7373
/// </summary>
74-
public IList<OpenApiSecurityRequirement>? Security { get; set; } =
75-
new List<OpenApiSecurityRequirement>();
74+
public IList<OpenApiSecurityRequirement>? Security { get; set; }
7675

7776
private HashSet<OpenApiTag>? _tags;
7877
/// <summary>
@@ -104,7 +103,7 @@ public ISet<OpenApiTag>? Tags
104103
/// <summary>
105104
/// This object MAY be extended with Specification Extensions.
106105
/// </summary>
107-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
106+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
108107

109108
/// <inheritdoc />
110109
public IDictionary<string, object>? Metadata { get; set; }

src/Microsoft.OpenApi/Models/OpenApiEncoding.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible
2525
/// <summary>
2626
/// A map allowing additional information to be provided as headers.
2727
/// </summary>
28-
public IDictionary<string, IOpenApiHeader>? Headers { get; set; } = new Dictionary<string, IOpenApiHeader>();
28+
public IDictionary<string, IOpenApiHeader>? Headers { get; set; }
2929

3030
/// <summary>
3131
/// Describes how a specific property value will be serialized depending on its type.
@@ -52,7 +52,7 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible
5252
/// <summary>
5353
/// This object MAY be extended with Specification Extensions.
5454
/// </summary>
55-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
55+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
5656

5757
/// <summary>
5858
/// Parameter-less constructor

src/Microsoft.OpenApi/Models/OpenApiExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Models
1313
/// <summary>
1414
/// Example Object.
1515
/// </summary>
16-
public class OpenApiExample : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiExample
16+
public class OpenApiExample : IOpenApiExtensible, IOpenApiExample
1717
{
1818
/// <inheritdoc/>
1919
public string? Summary { get; set; }
@@ -28,7 +28,7 @@ public class OpenApiExample : IOpenApiReferenceable, IOpenApiExtensible, IOpenAp
2828
public JsonNode? Value { get; set; }
2929

3030
/// <inheritdoc/>
31-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
31+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
3232

3333
/// <summary>
3434
/// Parameter-less constructor

src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class OpenApiExternalDocs : IOpenApiSerializable, IOpenApiExtensible
2626
/// <summary>
2727
/// This object MAY be extended with Specification Extensions.
2828
/// </summary>
29-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
29+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
3030

3131
/// <summary>
3232
/// Parameter-less constructor

src/Microsoft.OpenApi/Models/OpenApiHeader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public class OpenApiHeader : IOpenApiHeader, IOpenApiExtensible
4747
public JsonNode? Example { get; set; }
4848

4949
/// <inheritdoc/>
50-
public IDictionary<string, IOpenApiExample>? Examples { get; set; } = new Dictionary<string, IOpenApiExample>();
50+
public IDictionary<string, IOpenApiExample>? Examples { get; set; }
5151

5252
/// <inheritdoc/>
53-
public IDictionary<string, OpenApiMediaType>? Content { get; set; } = new Dictionary<string, OpenApiMediaType>();
53+
public IDictionary<string, OpenApiMediaType>? Content { get; set; }
5454

5555
/// <inheritdoc/>
56-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
56+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
5757

5858
/// <summary>
5959
/// Parameter-less constructor

src/Microsoft.OpenApi/Models/OpenApiInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class OpenApiInfo : IOpenApiSerializable, IOpenApiExtensible
5151
/// <summary>
5252
/// This object MAY be extended with Specification Extensions.
5353
/// </summary>
54-
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
54+
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }
5555

5656
/// <summary>
5757
/// Parameter-less constructor

0 commit comments

Comments
 (0)