Skip to content

Commit 392e5a7

Browse files
committed
chore: revert collections to use interface types
1 parent 1e65ae1 commit 392e5a7

23 files changed

+91
-92
lines changed

src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public override void Visit(OpenApiOperation operation)
7777
// Order matters. Resolve operationId.
7878
operationId = RemoveHashSuffix(operationId);
7979
if (operationTypeExtension.IsEquals("action") || operationTypeExtension.IsEquals("function"))
80-
operationId = RemoveKeyTypeSegment(operationId, operation.Parameters ?? []);
80+
operationId = RemoveKeyTypeSegment(operationId, operation.Parameters ?? new List<IOpenApiParameter>());
8181
operationId = SingularizeAndDeduplicateOperationId(operationId.SplitByChar('.'));
8282
operationId = ResolveODataCastOperationId(operationId);
8383
operationId = ResolveByRefOperationId(operationId);
@@ -145,7 +145,7 @@ private static string RemoveHashSuffix(string operationId)
145145
return s_hashSuffixRegex.Match(operationId).Value;
146146
}
147147

148-
private static string RemoveKeyTypeSegment(string operationId, List<IOpenApiParameter> parameters)
148+
private static string RemoveKeyTypeSegment(string operationId, IList<IOpenApiParameter> parameters)
149149
{
150150
var segments = operationId.SplitByChar('.');
151151
foreach (var parameter in parameters)
@@ -159,7 +159,7 @@ private static string RemoveKeyTypeSegment(string operationId, List<IOpenApiPara
159159
return string.Join('.', segments);
160160
}
161161

162-
private static void ResolveFunctionParameters(List<IOpenApiParameter> parameters)
162+
private static void ResolveFunctionParameters(IList<IOpenApiParameter> parameters)
163163
{
164164
foreach (var parameter in parameters.OfType<OpenApiParameter>().Where(static p => p.Content?.Count > 0))
165165
{

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public interface IOpenApiPathItem : IOpenApiDescribedElement, IOpenApiSummarized
1919
/// <summary>
2020
/// An alternative server array to service all operations in this path.
2121
/// </summary>
22-
public List<OpenApiServer>? Servers { get; }
22+
public IList<OpenApiServer>? Servers { get; }
2323

2424
/// <summary>
2525
/// A list of parameters that are applicable for all the operations described under this path.
2626
/// These parameters can be overridden at the operation level, but cannot be removed there.
2727
/// </summary>
28-
public List<IOpenApiParameter>? Parameters { get; }
28+
public IList<IOpenApiParameter>? Parameters { get; }
2929
}

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,19 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte
145145
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation
146146
/// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
147147
/// </summary>
148-
public List<IOpenApiSchema>? AllOf { get; }
148+
public IList<IOpenApiSchema>? AllOf { get; }
149149

150150
/// <summary>
151151
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation
152152
/// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
153153
/// </summary>
154-
public List<IOpenApiSchema>? OneOf { get; }
154+
public IList<IOpenApiSchema>? OneOf { get; }
155155

156156
/// <summary>
157157
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation
158158
/// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
159159
/// </summary>
160-
public List<IOpenApiSchema>? AnyOf { get; }
160+
public IList<IOpenApiSchema>? AnyOf { get; }
161161

162162
/// <summary>
163163
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation
@@ -168,7 +168,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte
168168
/// <summary>
169169
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation
170170
/// </summary>
171-
public HashSet<string>? Required { get; }
171+
public ISet<string>? Required { get; }
172172

173173
/// <summary>
174174
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation
@@ -247,12 +247,12 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte
247247
/// To represent examples that cannot be naturally represented in JSON or YAML,
248248
/// a list of values can be used to contain the examples with escaping where necessary.
249249
/// </summary>
250-
public List<JsonNode>? Examples { get; }
250+
public IList<JsonNode>? Examples { get; }
251251

252252
/// <summary>
253253
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation
254254
/// </summary>
255-
public List<JsonNode>? Enum { get; }
255+
public IList<JsonNode>? Enum { get; }
256256

257257
/// <summary>
258258
/// Follow JSON Schema definition: https://json-schema.org/draft/2020-12/json-schema-validation

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 5 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 List<OpenApiServer>? Servers { get; set; } = [];
52+
public IList<OpenApiServer>? Servers { get; set; } = [];
5353

5454
/// <summary>
5555
/// REQUIRED. The available paths and operations for the API.
@@ -71,13 +71,13 @@ public void RegisterComponents()
7171
/// <summary>
7272
/// A declaration of which security mechanisms can be used across the API.
7373
/// </summary>
74-
public List<OpenApiSecurityRequirement>? Security { get; set; }
74+
public IList<OpenApiSecurityRequirement>? Security { get; set; }
7575

76-
private HashSet<OpenApiTag>? _tags;
76+
private ISet<OpenApiTag>? _tags;
7777
/// <summary>
7878
/// A list of tags used by the specification with additional metadata.
7979
/// </summary>
80-
public HashSet<OpenApiTag>? Tags
80+
public ISet<OpenApiTag>? Tags
8181
{
8282
get
8383
{
@@ -414,7 +414,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
414414
return server.ReplaceServerUrlVariables([]);
415415
}
416416

417-
private static void WriteHostInfoV2(IOpenApiWriter writer, List<OpenApiServer>? servers)
417+
private static void WriteHostInfoV2(IOpenApiWriter writer, IList<OpenApiServer>? servers)
418418
{
419419
if (servers == null || !servers.Any())
420420
{

src/Microsoft.OpenApi/Models/OpenApiOperation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public class OpenApiOperation : IOpenApiSerializable, IOpenApiExtensible, IMetad
2222
/// </summary>
2323
public const bool DeprecatedDefault = false;
2424

25-
private HashSet<OpenApiTagReference>? _tags;
25+
private ISet<OpenApiTagReference>? _tags;
2626
/// <summary>
2727
/// A list of tags for API documentation control.
2828
/// Tags can be used for logical grouping of operations by resources or any other qualifier.
2929
/// </summary>
30-
public HashSet<OpenApiTagReference>? Tags
30+
public ISet<OpenApiTagReference>? Tags
3131
{
3232
get
3333
{
@@ -74,7 +74,7 @@ public HashSet<OpenApiTagReference>? Tags
7474
/// The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location.
7575
/// The list can use the Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters.
7676
/// </summary>
77-
public List<IOpenApiParameter>? Parameters { get; set; }
77+
public IList<IOpenApiParameter>? Parameters { get; set; }
7878

7979
/// <summary>
8080
/// The request body applicable for this operation.
@@ -111,14 +111,14 @@ public HashSet<OpenApiTagReference>? Tags
111111
/// This definition overrides any declared top-level security.
112112
/// To remove a top-level security declaration, an empty array can be used.
113113
/// </summary>
114-
public List<OpenApiSecurityRequirement>? Security { get; set; }
114+
public IList<OpenApiSecurityRequirement>? Security { get; set; }
115115

116116
/// <summary>
117117
/// An alternative server array to service this operation.
118118
/// If an alternative server object is specified at the Path Item Object or Root level,
119119
/// it will be overridden by this value.
120120
/// </summary>
121-
public List<OpenApiServer>? Servers { get; set; }
121+
public IList<OpenApiServer>? Servers { get; set; }
122122

123123
/// <summary>
124124
/// This object MAY be extended with Specification Extensions.
@@ -139,7 +139,7 @@ public OpenApiOperation() { }
139139
public OpenApiOperation(OpenApiOperation operation)
140140
{
141141
Utils.CheckArgumentNull(operation);
142-
Tags = operation.Tags != null ? [.. operation.Tags] : null;
142+
Tags = operation.Tags != null ? new HashSet<OpenApiTagReference>(operation.Tags) : null;
143143
Summary = operation.Summary ?? Summary;
144144
Description = operation.Description ?? Description;
145145
ExternalDocs = operation.ExternalDocs != null ? new(operation.ExternalDocs) : null;
@@ -357,7 +357,7 @@ public virtual void SerializeAsV2(IOpenApiWriter writer)
357357
writer.WriteEndObject();
358358
}
359359

360-
private static HashSet<OpenApiTagReference>? VerifyTagReferences(HashSet<OpenApiTagReference>? tags)
360+
private static ISet<OpenApiTagReference>? VerifyTagReferences(ISet<OpenApiTagReference>? tags)
361361
{
362362
if (tags?.Count > 0)
363363
{

src/Microsoft.OpenApi/Models/OpenApiPathItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiPathItem
2525
public Dictionary<HttpMethod, OpenApiOperation>? Operations { get; set; }
2626

2727
/// <inheritdoc/>
28-
public List<OpenApiServer>? Servers { get; set; }
28+
public IList<OpenApiServer>? Servers { get; set; }
2929

3030
/// <inheritdoc/>
31-
public List<IOpenApiParameter>? Parameters { get; set; }
31+
public IList<IOpenApiParameter>? Parameters { get; set; }
3232

3333
/// <inheritdoc/>
3434
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; }

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,19 @@ public string? Minimum
180180
public bool WriteOnly { get; set; }
181181

182182
/// <inheritdoc />
183-
public List<IOpenApiSchema>? AllOf { get; set; }
183+
public IList<IOpenApiSchema>? AllOf { get; set; }
184184

185185
/// <inheritdoc />
186-
public List<IOpenApiSchema>? OneOf { get; set; }
186+
public IList<IOpenApiSchema>? OneOf { get; set; }
187187

188188
/// <inheritdoc />
189-
public List<IOpenApiSchema>? AnyOf { get; set; }
189+
public IList<IOpenApiSchema>? AnyOf { get; set; }
190190

191191
/// <inheritdoc />
192192
public IOpenApiSchema? Not { get; set; }
193193

194194
/// <inheritdoc />
195-
public HashSet<string>? Required { get; set; }
195+
public ISet<string>? Required { get; set; }
196196

197197
/// <inheritdoc />
198198
public IOpenApiSchema? Items { get; set; }
@@ -231,10 +231,10 @@ public string? Minimum
231231
public JsonNode? Example { get; set; }
232232

233233
/// <inheritdoc />
234-
public List<JsonNode>? Examples { get; set; }
234+
public IList<JsonNode>? Examples { get; set; }
235235

236236
/// <inheritdoc />
237-
public List<JsonNode>? Enum { get; set; }
237+
public IList<JsonNode>? Enum { get; set; }
238238

239239
/// <inheritdoc />
240240
public bool UnevaluatedProperties { get; set; }
@@ -305,7 +305,7 @@ internal OpenApiSchema(IOpenApiSchema schema)
305305
OneOf = schema.OneOf != null ? [.. schema.OneOf] : null;
306306
AnyOf = schema.AnyOf != null ? [.. schema.AnyOf] : null;
307307
Not = schema.Not?.CreateShallowCopy();
308-
Required = schema.Required != null ? [.. schema.Required] : null;
308+
Required = schema.Required != null ? new HashSet<string>(schema.Required) : null;
309309
Items = schema.Items?.CreateShallowCopy();
310310
MaxItems = schema.MaxItems ?? MaxItems;
311311
MinItems = schema.MinItems ?? MinItems;
@@ -625,7 +625,7 @@ private void WriteFormatProperty(IOpenApiWriter writer)
625625
/// <param name="propertyName">The property name that will be serialized.</param>
626626
private void SerializeAsV2(
627627
IOpenApiWriter writer,
628-
HashSet<string>? parentRequiredProperties,
628+
ISet<string>? parentRequiredProperties,
629629
string? propertyName)
630630
{
631631
parentRequiredProperties ??= new HashSet<string>();

src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public string? Description
5656
public Dictionary<HttpMethod, OpenApiOperation>? Operations { get => Target?.Operations; }
5757

5858
/// <inheritdoc/>
59-
public List<OpenApiServer>? Servers { get => Target?.Servers; }
59+
public IList<OpenApiServer>? Servers { get => Target?.Servers; }
6060

6161
/// <inheritdoc/>
62-
public List<IOpenApiParameter>? Parameters { get => Target?.Parameters; }
62+
public IList<IOpenApiParameter>? Parameters { get => Target?.Parameters; }
6363

6464
/// <inheritdoc/>
6565
public IDictionary<string, IOpenApiExtension>? Extensions { get => Target?.Extensions; }

src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ public string? Description
8888
/// <inheritdoc/>
8989
public bool WriteOnly { get => Target?.WriteOnly ?? false; }
9090
/// <inheritdoc/>
91-
public List<IOpenApiSchema>? AllOf { get => Target?.AllOf; }
91+
public IList<IOpenApiSchema>? AllOf { get => Target?.AllOf; }
9292
/// <inheritdoc/>
93-
public List<IOpenApiSchema>? OneOf { get => Target?.OneOf; }
93+
public IList<IOpenApiSchema>? OneOf { get => Target?.OneOf; }
9494
/// <inheritdoc/>
95-
public List<IOpenApiSchema>? AnyOf { get => Target?.AnyOf; }
95+
public IList<IOpenApiSchema>? AnyOf { get => Target?.AnyOf; }
9696
/// <inheritdoc/>
9797
public IOpenApiSchema? Not { get => Target?.Not; }
9898
/// <inheritdoc/>
99-
public HashSet<string>? Required { get => Target?.Required; }
99+
public ISet<string>? Required { get => Target?.Required; }
100100
/// <inheritdoc/>
101101
public IOpenApiSchema? Items { get => Target?.Items; }
102102
/// <inheritdoc/>
@@ -122,9 +122,9 @@ public string? Description
122122
/// <inheritdoc/>
123123
public JsonNode? Example { get => Target?.Example; }
124124
/// <inheritdoc/>
125-
public List<JsonNode>? Examples { get => Target?.Examples; }
125+
public IList<JsonNode>? Examples { get => Target?.Examples; }
126126
/// <inheritdoc/>
127-
public List<JsonNode>? Enum { get => Target?.Enum; }
127+
public IList<JsonNode>? Enum { get => Target?.Enum; }
128128
/// <inheritdoc/>
129129
public bool UnevaluatedProperties { get => Target?.UnevaluatedProperties ?? false; }
130130
/// <inheritdoc/>

src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public class OpenApiDiagnostic : IDiagnostic
1515
/// <summary>
1616
/// List of all errors.
1717
/// </summary>
18-
public List<OpenApiError> Errors { get; set; } = [];
18+
public IList<OpenApiError> Errors { get; set; } = [];
1919

2020
/// <summary>
2121
/// List of all warnings
2222
/// </summary>
23-
public List<OpenApiError> Warnings { get; set; } = [];
23+
public IList<OpenApiError> Warnings { get; set; } = [];
2424

2525
/// <summary>
2626
/// Open API specification version of the document parsed.

src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ internal static partial class OpenApiV2Deserializer
117117
{s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
118118
};
119119

120-
private static void MakeServers(List<OpenApiServer> servers, ParsingContext context, RootNode rootNode)
120+
private static void MakeServers(IList<OpenApiServer> servers, ParsingContext context, RootNode rootNode)
121121
{
122122
var host = context.GetFromTempStorage<string>("host");
123123
var basePath = context.GetFromTempStorage<string>("basePath");

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public static OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(Dictionary<string, Ope
230230
return operations;
231231
}
232232

233-
private static List<SearchResult> FindOperations(OpenApiDocument sourceDocument, Func<string, HttpMethod, OpenApiOperation, bool> predicate)
233+
private static IList<SearchResult> FindOperations(OpenApiDocument sourceDocument, Func<string, HttpMethod, OpenApiOperation, bool> predicate)
234234
{
235235
var search = new OperationSearch(predicate);
236236
var walker = new OpenApiWalker(search);
@@ -354,7 +354,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon
354354
return moreStuff;
355355
}
356356

357-
private static string ExtractPath(string url, List<OpenApiServer>? serverList)
357+
private static string ExtractPath(string url, IList<OpenApiServer>? serverList)
358358
{
359359
// if OpenAPI has servers, then see if the url matches one of them
360360
var baseUrl = serverList?.Select(s => s.Url?.TrimEnd('/'))

src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public virtual void Visit(OpenApiLicense license)
8686
/// <summary>
8787
/// Visits list of <see cref="OpenApiServer"/>
8888
/// </summary>
89-
public virtual void Visit(List<OpenApiServer> servers)
89+
public virtual void Visit(IList<OpenApiServer> servers)
9090
{
9191
}
9292

@@ -142,7 +142,7 @@ public virtual void Visit(OpenApiOperation operation)
142142
/// <summary>
143143
/// Visits list of <see cref="OpenApiParameter"/>
144144
/// </summary>
145-
public virtual void Visit(List<IOpenApiParameter> parameters)
145+
public virtual void Visit(IList<IOpenApiParameter> parameters)
146146
{
147147
}
148148

@@ -310,21 +310,21 @@ public virtual void Visit(IOpenApiExample example)
310310
/// <summary>
311311
/// Visits list of <see cref="OpenApiTag"/>
312312
/// </summary>
313-
public virtual void Visit(HashSet<OpenApiTag> openApiTags)
313+
public virtual void Visit(ISet<OpenApiTag> openApiTags)
314314
{
315315
}
316316

317317
/// <summary>
318318
/// Visits list of <see cref="OpenApiTagReference"/>
319319
/// </summary>
320-
public virtual void Visit(HashSet<OpenApiTagReference> openApiTags)
320+
public virtual void Visit(ISet<OpenApiTagReference> openApiTags)
321321
{
322322
}
323323

324324
/// <summary>
325325
/// Visits list of <see cref="OpenApiSecurityRequirement"/>
326326
/// </summary>
327-
public virtual void Visit(List<OpenApiSecurityRequirement> openApiSecurityRequirements)
327+
public virtual void Visit(IList<OpenApiSecurityRequirement> openApiSecurityRequirements)
328328
{
329329
}
330330

0 commit comments

Comments
 (0)